Class: Transfer::Generators::Mongoid
- Defined in:
- lib/transfer/generators/mongoid.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
#after, #before, #column_present?, #initialize
Constructor Details
This class inherits a constructor from Transfer::Generators::Base
Class Method Details
Instance Method Details
#create(attributes, row, options = {}, callbacks = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/transfer/generators/mongoid.rb', line 13 def create attributes, row, ={}, callbacks={} model = klass.new attributes, :without_protection => true model.instance_exec(row, &callbacks[:before_save]) if callbacks[:before_save] = .select{|key| key == :validate } model.save! [:success].call(model, row) if [:success] model.instance_exec(row, &callbacks[:after_save]) if callbacks[:after_save] model rescue Exception => e [:failure].call(model, row, e) if [:failure] raise if [:failure_strategy] == :rollback model end |
#transaction ⇒ Object
7 8 9 10 11 |
# File 'lib/transfer/generators/mongoid.rb', line 7 def transaction yield rescue klass.delete_all end |