class RKS::Support::Routable::Router

Attributes

owner[RW]
routes[RW]

Public Class Methods

new(owner:) click to toggle source
# File lib/rks/support/routable.rb, line 19
def initialize(owner:)
  @owner = owner
  @routes = {}
end

Public Instance Methods

draw() { |self| ... } click to toggle source
# File lib/rks/support/routable.rb, line 32
def draw
  yield(self)
end
find(name) click to toggle source
# 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: {}) click to toggle source
# 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: options}})
end