Class: FactoryGirl::Proxy
- Inherits:
-
Object
- Object
- FactoryGirl::Proxy
- Defined in:
- lib/factory_girl/proxy.rb,
lib/factory_girl/proxy/stub.rb,
lib/factory_girl/proxy/build.rb,
lib/factory_girl/proxy/create.rb,
lib/factory_girl/proxy/attributes_for.rb
Overview
:nodoc:
Direct Known Subclasses
Defined Under Namespace
Classes: AttributesFor, Build, Create, Stub
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
Instance Method Summary collapse
- #add_callback(name, block) ⇒ Object
- #associate(name, factory, attributes) ⇒ Object
-
#association(name, overrides = {}) ⇒ Object
Generates an association using the current build strategy.
- #get(attribute) ⇒ Object
-
#initialize(klass) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(method, *args, &block) ⇒ Object
- #result(to_create) ⇒ Object
- #run_callbacks(name) ⇒ Object
- #set(attribute, value, ignored = false) ⇒ Object
Constructor Details
#initialize(klass) ⇒ Proxy
Returns a new instance of Proxy.
6 7 |
# File 'lib/factory_girl/proxy.rb', line 6 def initialize(klass) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
71 72 73 |
# File 'lib/factory_girl/proxy.rb', line 71 def method_missing(method, *args, &block) get(method) end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
4 5 6 |
# File 'lib/factory_girl/proxy.rb', line 4 def callbacks @callbacks end |
Instance Method Details
#add_callback(name, block) ⇒ Object
18 19 20 21 22 |
# File 'lib/factory_girl/proxy.rb', line 18 def add_callback(name, block) @callbacks ||= {} @callbacks[name] ||= [] @callbacks[name] << block end |
#associate(name, factory, attributes) ⇒ Object
15 16 |
# File 'lib/factory_girl/proxy.rb', line 15 def associate(name, factory, attributes) end |
#association(name, overrides = {}) ⇒ Object
Generates an association using the current build strategy.
Arguments:
name: (Symbol)
The name of the factory that should be used to generate this
association.
attributes: (Hash)
A hash of attributes that should be overridden for this association.
Returns:
The generated association for the current build strategy. Note that
associations are not generated for the attributes_for strategy. Returns
nil in this case.
Example:
factory :user do
# ...
end
factory :post do
# ...
{ |post| post.association(:user, :name => 'Joe') }
end
# Builds (but doesn't save) a Post and a User
FactoryGirl.build(:post)
# Builds and saves a User, builds a Post, assigns the User to the
# author association, and saves the Post.
FactoryGirl.create(:post)
68 69 |
# File 'lib/factory_girl/proxy.rb', line 68 def association(name, overrides = {}) end |
#get(attribute) ⇒ Object
9 10 |
# File 'lib/factory_girl/proxy.rb', line 9 def get(attribute) end |
#result(to_create) ⇒ Object
75 76 77 |
# File 'lib/factory_girl/proxy.rb', line 75 def result(to_create) raise NotImplementedError, "Strategies must return a result" end |
#run_callbacks(name) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/factory_girl/proxy.rb', line 24 def run_callbacks(name) if @callbacks && @callbacks[name] @callbacks[name].each do |block| case block.arity when 0 then block.call when 2 then block.call(@instance, self) else block.call(@instance) end end end end |
#set(attribute, value, ignored = false) ⇒ Object
12 13 |
# File 'lib/factory_girl/proxy.rb', line 12 def set(attribute, value, ignored = false) end |