Class: AnonymousActiveRecord::Factory
- Inherits:
-
Object
- Object
- AnonymousActiveRecord::Factory
- Defined in:
- lib/anonymous_active_record/factory.rb
Overview
Factory initializes instances of a pseudo anonymous class in a particular namespace of your choosing.
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#initialize(source_data, klass) ⇒ Factory
constructor
A new instance of Factory.
- #run ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(source_data, klass) ⇒ Factory
Returns a new instance of Factory.
17 18 19 20 |
# File 'lib/anonymous_active_record/factory.rb', line 17 def initialize(source_data, klass) @source_data = source_data # an array of hashes @klass = klass end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
15 16 17 |
# File 'lib/anonymous_active_record/factory.rb', line 15 def klass @klass end |
Instance Method Details
#run ⇒ Object
22 23 24 25 26 |
# File 'lib/anonymous_active_record/factory.rb', line 22 def run @source_data.map do |hash| klass.create(hash) end end |
#run! ⇒ Object
28 29 30 31 32 |
# File 'lib/anonymous_active_record/factory.rb', line 28 def run! @source_data.map do |hash| klass.create!(hash) end end |