Class: RequestRegistry

Inherits:
Module
  • Object
show all
Defined in:
lib/request_registry.rb

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Constructor Details

#initialize(*method_list) ⇒ RequestRegistry

Returns a new instance of RequestRegistry.



3
4
5
# File 'lib/request_registry.rb', line 3

def initialize(*method_list)
  @method_list = method_list
end

Instance Method Details

#extended(object) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/request_registry.rb', line 7

def extended(object)
  method_list = @method_list
  object.instance_variable_set '@request_registry_key', object.name.freeze
  object.class_eval do
    attr_accessor(*method_list)
  end
  object.singleton_class.class_eval do
    define_method :instance do
      RequestStore.store[@request_registry_key] ||= object.new
    end
    object.public_instance_methods(false).each do |method|
      define_method method do |*args|
        instance.send(method, *args)
      end
    end
  end
end