class FactoryGirl::Factory::Runner
Public Class Methods
new(options = {})
click to toggle source
# File lib/factory_girl/factory.rb, line 147 def initialize(options = {}) @attributes = options[:attributes] @callbacks = options[:callbacks] @to_create = options[:to_create] @build_class = options[:build_class] @proxy_class = options[:proxy_class] @overrides = {} end
Public Instance Methods
run(overrides = {})
click to toggle source
# File lib/factory_girl/factory.rb, line 157 def run(overrides = {}) @overrides = overrides.symbolize_keys apply_attributes apply_remaining_overrides proxy.result(@to_create) end
Private Instance Methods
add_static_attribute(attr, val, ignored = false)
click to toggle source
# File lib/factory_girl/factory.rb, line 193 def add_static_attribute(attr, val, ignored = false) Attribute::Static.new(attr, val, ignored).add_to(proxy) end
apply_attributes()
click to toggle source
# File lib/factory_girl/factory.rb, line 168 def apply_attributes @attributes.each do |attribute| if overrides_for_attribute(attribute).any? handle_attribute_with_overrides(attribute) else handle_attribute_without_overrides(attribute) end end end
apply_remaining_overrides()
click to toggle source
# File lib/factory_girl/factory.rb, line 178 def apply_remaining_overrides @overrides.each { |attr, val| add_static_attribute(attr, val) } end
handle_attribute_with_overrides(attribute)
click to toggle source
# File lib/factory_girl/factory.rb, line 186 def handle_attribute_with_overrides(attribute) overrides_for_attribute(attribute).each do |attr, val| add_static_attribute(attr, val, attribute.ignored) @overrides.delete(attr) end end
handle_attribute_without_overrides(attribute)
click to toggle source
# File lib/factory_girl/factory.rb, line 197 def handle_attribute_without_overrides(attribute) attribute.add_to(proxy) end
overrides_for_attribute(attribute)
click to toggle source
# File lib/factory_girl/factory.rb, line 182 def overrides_for_attribute(attribute) @overrides.select { |attr, val| attribute.alias_for?(attr) } end
proxy()
click to toggle source
# File lib/factory_girl/factory.rb, line 201 def proxy @proxy ||= @proxy_class.new(@build_class, @callbacks) end