Class: Factory::Proxy::Build

Inherits:
Factory::Proxy show all
Defined in:
lib/factory_girl/proxy/build.rb

Overview

:nodoc:

Direct Known Subclasses

Create

Instance Attribute Summary

Attributes inherited from Factory::Proxy

#callbacks

Instance Method Summary collapse

Methods inherited from Factory::Proxy

#add_callback, #method_missing, #run_callbacks

Constructor Details

#initialize(klass) ⇒ Build

Returns a new instance of Build.



4
5
6
# File 'lib/factory_girl/proxy/build.rb', line 4

def initialize(klass)
  @instance = klass.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Factory::Proxy

Instance Method Details

#associate(name, factory, attributes) ⇒ Object



16
17
18
# File 'lib/factory_girl/proxy/build.rb', line 16

def associate(name, factory, attributes)
  set(name, Factory.create(factory, attributes))
end

#association(factory, overrides = {}) ⇒ Object



20
21
22
# File 'lib/factory_girl/proxy/build.rb', line 20

def association(factory, overrides = {})
  Factory.create(factory, overrides)
end

#get(attribute) ⇒ Object



8
9
10
# File 'lib/factory_girl/proxy/build.rb', line 8

def get(attribute)
  @instance.send(attribute)
end

#resultObject



24
25
26
27
# File 'lib/factory_girl/proxy/build.rb', line 24

def result
  run_callbacks(:after_build)
  @instance
end

#set(attribute, value) ⇒ Object



12
13
14
# File 'lib/factory_girl/proxy/build.rb', line 12

def set(attribute, value)
  @instance.send(:"#{attribute}=", value)
end