Class: Inject::Injector

Inherits:
Hash
  • Object
show all
Defined in:
lib/attr_inject/injector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/attr_inject/injector.rb', line 5

def parent
  @parent
end

Instance Method Details

#apply(target) ⇒ Object



16
17
18
19
# File 'lib/attr_inject/injector.rb', line 16

def apply(target)
  hash = parent ? parent.merge(self) : self
  target.inject_attributes hash
end

#factory(key, &block) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/attr_inject/injector.rb', line 11

def factory(key, &block)
  raise ArgumentError, "Block is required for factories." if block.nil?
  self[key] = block
end

#map(key, val) ⇒ Object



7
8
9
# File 'lib/attr_inject/injector.rb', line 7

def map(key, val)
  self[key] = val
end