Class: FactoryGroup::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_group/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGroup

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

#factoriesObject (readonly)

Returns the value of attribute factories.



11
12
13
# File 'lib/factory_group/group.rb', line 11

def factories
  @factories
end