Class: FactoryGirl::Proxy::Build

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

Overview

:nodoc:

Direct Known Subclasses

Create

Instance Attribute Summary

Attributes inherited from FactoryGirl::Proxy

#callbacks

Instance Method Summary collapse

Methods inherited from FactoryGirl::Proxy

#add_callback, #method_missing, #run_callbacks

Constructor Details

#initialize(klass) ⇒ Build

Returns a new instance of Build.



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

def initialize(klass)
  @instance = klass.new
  @ignored_attributes = {}
end

Dynamic Method Handling

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

Instance Method Details

#associate(name, factory_name, overrides) ⇒ Object



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

def associate(name, factory_name, overrides)
  factory = FactoryGirl.factory_by_name(factory_name)
  set(name, factory.run(Proxy::Create, overrides))
end

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



30
31
32
33
# File 'lib/factory_girl/proxy/build.rb', line 30

def association(factory_name, overrides = {})
  factory = FactoryGirl.factory_by_name(factory_name)
  factory.run(Proxy::Create, overrides)
end

#get(attribute) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/factory_girl/proxy/build.rb', line 9

def get(attribute)
  if @ignored_attributes.has_key?(attribute)
    @ignored_attributes[attribute]
  else
    @instance.send(attribute)
  end
end

#result(to_create) ⇒ Object



35
36
37
38
# File 'lib/factory_girl/proxy/build.rb', line 35

def result(to_create)
  run_callbacks(:after_build)
  @instance
end

#set(attribute, value, ignored = false) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/factory_girl/proxy/build.rb', line 17

def set(attribute, value, ignored = false)
  if ignored
    @ignored_attributes[attribute] = value
  else
    @instance.send(:"#{attribute}=", value)
  end
end