Class: RKS::Support::Routable::Router
- Inherits:
-
Object
- Object
- RKS::Support::Routable::Router
- Defined in:
- lib/rks/support/routable.rb
Defined Under Namespace
Classes: RouteNotFound
Instance Attribute Summary collapse
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #draw {|_self| ... } ⇒ Object
- #find(name) ⇒ Object
-
#initialize(owner:) ⇒ Router
constructor
A new instance of Router.
- #on(name, to:, options: {}) ⇒ Object
Constructor Details
#initialize(owner:) ⇒ Router
Returns a new instance of Router.
19 20 21 22 |
# File 'lib/rks/support/routable.rb', line 19 def initialize(owner:) @owner = owner @routes = {} end |
Instance Attribute Details
#owner ⇒ Object
Returns the value of attribute owner.
17 18 19 |
# File 'lib/rks/support/routable.rb', line 17 def owner @owner end |
#routes ⇒ Object
Returns the value of attribute routes.
17 18 19 |
# File 'lib/rks/support/routable.rb', line 17 def routes @routes end |
Instance Method Details
#draw {|_self| ... } ⇒ Object
32 33 34 |
# File 'lib/rks/support/routable.rb', line 32 def draw yield(self) end |
#find(name) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rks/support/routable.rb', line 24 def find(name) if route = routes[name] route else raise RouteNotFound, "#{name} is not found in #{owner} routes" end end |
#on(name, to:, options: {}) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rks/support/routable.rb', line 36 def on(name, to:, options: {}) klass_name, action = to.split('#') klass = Object.const_get(klass_name) block = Proc.new { |correlation_id, payload| klass.new(correlation_id: correlation_id, payload: payload).send(action.to_sym) } routes.merge!({name => {block: block, options: }}) end |