Class: Rubory::CreationDsl

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factory, context) ⇒ CreationDsl

Returns a new instance of CreationDsl.



65
66
67
68
# File 'lib/factories.rb', line 65

def initialize(factory, context)
  @factory = factory
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &creation_block) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/factories.rb', line 74

def method_missing(method, *args, &creation_block)
  if block_given?
    @factory.value_for(method, &creation_block)
  else
    @factory.value_for(method) { args.first }
  end
end

Class Method Details

.create_factory(name, context, &definition) ⇒ Object



69
70
71
72
73
# File 'lib/factories.rb', line 69

def self.create_factory(name,context, &definition)
  f = Factory.new(name, context)
  definition.call(new(f,context))
  return f
end

Instance Method Details

#associate(factory_name) ⇒ Object



81
82
83
# File 'lib/factories.rb', line 81

def associate(factory_name)
  @factory.value_for(factory_name) { @context.create(factory_name) }
end