Class: FactoryGroup::Group
- Inherits:
-
Object
- Object
- FactoryGroup::Group
- Defined in:
- lib/factory_group/group.rb
Instance Attribute Summary collapse
-
#factories ⇒ Object
readonly
Returns the value of attribute factories.
Instance Method Summary collapse
-
#initialize ⇒ Group
constructor
A new instance of Group.
-
#method_missing(name, *args, &block) ⇒ Object
Sets an instance variable with the name as the called method and assigns the args passed to it.
Constructor Details
#initialize ⇒ Group
Returns a new instance of Group.
7 8 9 |
# File 'lib/factory_group/group.rb', line 7 def initialize @factories = OpenStruct.new({}) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Sets an instance variable with the name as the called method and assigns the args passed to it.
15 16 17 18 19 20 |
# File 'lib/factory_group/group.rb', line 15 def method_missing(name, *args, &block) # If the args is empty, it means a variable is reused inside the group itself evaluvated_result = args.empty? ? @factories.instance_eval(name.to_s) : args[0] @factories.send("#{name.to_s}=", evaluvated_result) end |
Instance Attribute Details
#factories ⇒ Object (readonly)
Returns the value of attribute factories.
11 12 13 |
# File 'lib/factory_group/group.rb', line 11 def factories @factories end |