Class FixtureReplacementController::ActiveRecordFactory
In: lib/fixture_replacement/controller/active_record_factory.rb
Parent: Object

I am a Factory which creates ActiveRecord Class instances. Give me a collection of attributes, and an additional hash, and I will merge them into a new ActiveRecord Instance (either a new instance with ActiveRecord::Base#new, or a created one ActiveRecord::Base#create!).

Methods

Public Class methods

[Source]

    # File lib/fixture_replacement/controller/active_record_factory.rb, line 8
 8:     def initialize(attributes, hash={}, original_caller=self)
 9:       @attributes = attributes
10:       @hash_given_to_constructor = hash
11:       @caller = original_caller
12:     end

Public Instance methods

[Source]

    # File lib/fixture_replacement/controller/active_record_factory.rb, line 20
20:     def to_created_instance
21:       created_obj = self.to_new_instance
22:       created_obj.save!
23:       return created_obj
24:     end

[Source]

    # File lib/fixture_replacement/controller/active_record_factory.rb, line 14
14:     def to_new_instance
15:       new_object = @attributes.active_record_class.new
16:       assign_values_to_instance new_object
17:       return new_object
18:     end

Protected Instance methods

[Source]

    # File lib/fixture_replacement/controller/active_record_factory.rb, line 28
28:     def hash_given_to_constructor
29:       @hash_given_to_constructor || Hash.new
30:     end

[Validate]