module SubZero::Service::Router

Public Instance Methods

route(&block) click to toggle source
# File lib/sub_zero/service/router.rb, line 11
def route &block
  instance_eval &block
end
routes() click to toggle source
# File lib/sub_zero/service/router.rb, line 7
def routes
  @routes ||= {}
end
verb(args) click to toggle source
# File lib/sub_zero/service/router.rb, line 15
def verb args
  name, route = Hash[args].first
  routes[name.to_s.upcase] = handler_caller(route)

  true
end

Private Instance Methods

handler_caller(route) click to toggle source
# File lib/sub_zero/service/router.rb, line 24
def handler_caller route
  handler, action = route.to_s.split('#')

  begin
    handler_name  = "Handlers::#{handler.camelize}"
    handler_class = const_get(handler_name)
  rescue
    fail "Handler not found: #{handler_name}"
  end

  proc { |message| handler_class.new(message).send action }
end