Class: Trowel::Sow
- Inherits:
-
Object
- Object
- Trowel::Sow
- Defined in:
- lib/trowel/sow.rb
Defined Under Namespace
Classes: RecordNotSaved
Instance Method Summary collapse
-
#initialize(path, options = {}) ⇒ Sow
constructor
A new instance of Sow.
Constructor Details
#initialize(path, options = {}) ⇒ Sow
Returns a new instance of Sow.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/trowel/sow.rb', line 3 def initialize(path, = {}) @path, @options = path, $stdout << "[Trowel::Sow] Seeding #{klass} from #{path}\n" if [:verbose] YAML::load_file(path).each do |attributes| object = klass.new attributes.each { |k,v| object.send("#{k}=", v) } begin process_callback(:before_save, object) object.save! process_callback(:after_save, object) rescue => e # ActiveRecord::RecordInvalid, SuperModel::InvalidRecord = e. + "\n[FATAL] Error saving #{object} with attributes: #{object.attributes.inspect}" raise(RecordNotSaved, ) end end end |