Sha256: 118b8a237911fa5c0582e141c13f3858c4700e99ef750ca80465e92255180d93

Contents?: true

Size: 761 Bytes

Versions: 2

Compression:

Stored size: 761 Bytes

Contents

module Rack::AMF
  class ServiceManager
    def initialize
      @services = {}
    end

    def register path, service
      @services ||= {}
      @services[path] = service
    end

    def handle env
      env['amf.response'].each_method_call do |method, args|
        handle_method method, args
      end
    end

    private
    def handle_method method, args
      path = method.split('.')
      method_name = path.pop
      path = path.join('.')

      if @services[path]
        if @services[path].respond_to?(method_name)
          @services[path].send(method_name, *args)
        else
          raise "Service #{path} does not respond to #{method_name}"
        end
      else
        raise "Service #{path} does not exist"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rack-amf-0.0.2 lib/rack/amf/service_manager.rb
rack-amf-0.0.1 lib/rack/amf/service_manager.rb