Class: Seedie::Model::Creator
- Inherits:
-
Object
- Object
- Seedie::Model::Creator
- Includes:
- Reporters::Reportable
- Defined in:
- lib/seedie/model/creator.rb
Instance Method Summary collapse
- #create(field_values_set) ⇒ Object
- #create!(field_values_set) ⇒ Object
-
#initialize(model, reporters = []) ⇒ Creator
constructor
A new instance of Creator.
Methods included from Reporters::Reportable
Constructor Details
#initialize(model, reporters = []) ⇒ Creator
Returns a new instance of Creator.
8 9 10 11 12 13 |
# File 'lib/seedie/model/creator.rb', line 8 def initialize(model, reporters = []) @model = model @reporters = reporters add_observers(@reporters) end |
Instance Method Details
#create(field_values_set) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/seedie/model/creator.rb', line 22 def create(field_values_set) begin create!(field_values_set) rescue ActiveRecord::RecordInvalid => e report(:record_invalid, record: e.record) nil end end |
#create!(field_values_set) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/seedie/model/creator.rb', line 15 def create!(field_values_set) record = @model.create!(field_values_set) report(:record_created, name: record.class.to_s, id: record.id.to_s) record end |