Sha256: 3b4ae506cda80262a049d11e06fcfdf9b16b97a810edc1a8710031642ec7245e

Contents?: true

Size: 988 Bytes

Versions: 2

Compression:

Stored size: 988 Bytes

Contents

module ExtDirect
  module Service
    class Provider
      @@store = {}
      
      class << self
        def register(type, action, method, proc)
          action = action.to_sym
          method = method.to_sym
          
          @@store[action] = {} unless @@store[action]
          @@store[action][method] = {} unless @@store[action][method]
          @@store[action][method][:type] = type
          @@store[action][method][:proc] = proc
        end
        
        def exist?(action, method)
          (@@store[action.to_sym] and @@store[action.to_sym][method.to_sym])
        end
        
        def type_of(action, method)
          false unless exist?(action, method)
          @@store[action.to_sym][method.to_sym][:type]
        end
        
        def execute(action, method, params = nil)
          raise "Unknown action or method" unless exist?(action, method)
          @@store[action.to_sym][method.to_sym][:proc].call(params)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ext_direct-0.1.1 lib/ext_direct/service/provider.rb
ext_direct-0.1.0 lib/ext_direct/service/provider.rb