Sha256: c4bcf20b8bbf6bb69fe4f27b4efd3685c5598058742970e091363d173d7cf58d

Contents?: true

Size: 735 Bytes

Versions: 5

Compression:

Stored size: 735 Bytes

Contents

require 'active_support/inflector'

module SubZero
  module Service
    module Router

      def routes
        @routes ||= {}
      end

      def route &block
        instance_eval &block
      end

      def verb args
        name, route = Hash[args].first
        routes[name.to_s.upcase] = handler_caller(route)

        true
      end

      private

      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

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sub_zero-0.0.9 lib/sub_zero/service/router.rb
sub_zero-0.0.8 lib/sub_zero/service/router.rb
sub_zero-0.0.7 lib/sub_zero/service/router.rb
sub_zero-0.0.6 lib/sub_zero/service/router.rb
sub_zero-0.0.5 lib/sub_zero/service/router.rb