Skip to content

Commit

Permalink
Create router class
Browse files Browse the repository at this point in the history
  • Loading branch information
apexatoll committed Sep 22, 2023
1 parent 78c5a64 commit aafb730
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/kangaru/router.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Kangaru
class Router
using Patches::Constantise

attr_reader :command, :namespace

def initialize(command, namespace: Object)
@command = command
@namespace = namespace
end
end
end
8 changes: 8 additions & 0 deletions sig/kangaru/router.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Kangaru
class Router
attr_reader command: Command
attr_reader namespace: Module

def initialize: (Command, ?namespace: Module) -> void
end
end
19 changes: 19 additions & 0 deletions spec/kangaru/router_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
RSpec.describe Kangaru::Router do
subject(:router) { described_class.new(command, namespace:) }

let(:command) { instance_double(Kangaru::Command, controller:, action:) }

let(:controller) { "SomeController" }

let(:action) { :some_action }

let(:namespace) { SomeNamespace }

before { stub_const "SomeNamespace", Module.new }

describe "#initialize" do
it "sets the attributes" do
expect(router).to have_attributes(command:, namespace:)
end
end
end

0 comments on commit aafb730

Please sign in to comment.