Module: Callme::Inject

Defined in:
lib/callme/inject.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/callme/inject.rb', line 16

def self.included(base)
  base.instance_eval do
    def inject(dependency_name, options = {})
      unless dependency_name.is_a?(Symbol)
        raise ArgumentError, "dependency name should be a symbol"
      end
      unless options.is_a?(Hash)
        raise ArgumentError, "second argument for inject method should be a Hash"
      end
      unless respond_to?(:_callme_injectable_attrs)
        class_attribute :_callme_injectable_attrs
        self._callme_injectable_attrs = { dependency_name => options.dup }
      else
        self._callme_injectable_attrs =
          self._callme_injectable_attrs.merge(dependency_name => options.dup)
      end
      attr_accessor dependency_name
    end
  end
end