Class: Factory
- Inherits:
-
Object
- Object
- Factory
- Defined in:
- lib/factory_hero/factory.rb
Instance Attribute Summary collapse
-
#default_attributes ⇒ Object
readonly
Returns the value of attribute default_attributes.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #build(attributes = {}) ⇒ Object
-
#initialize(symbol, options = {}, &block) ⇒ Factory
constructor
A new instance of Factory.
-
#method_missing(method, *args) ⇒ Object
used to assign default attributes.
Constructor Details
#initialize(symbol, options = {}, &block) ⇒ Factory
Returns a new instance of Factory.
5 6 7 8 9 10 11 |
# File 'lib/factory_hero/factory.rb', line 5 def initialize symbol, = {}, &block @symbol = symbol @default_attributes = {} @options = instance_eval(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
used to assign default attributes
21 22 23 |
# File 'lib/factory_hero/factory.rb', line 21 def method_missing(method, *args) @default_attributes[method] = args.first end |
Instance Attribute Details
#default_attributes ⇒ Object (readonly)
Returns the value of attribute default_attributes.
3 4 5 |
# File 'lib/factory_hero/factory.rb', line 3 def default_attributes @default_attributes end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
3 4 5 |
# File 'lib/factory_hero/factory.rb', line 3 def symbol @symbol end |
Instance Method Details
#build(attributes = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/factory_hero/factory.rb', line 13 def build attributes = {} build_object.tap do |obj| assign_attributes default_attributes assign_attributes attributes end end |