Module: DataMapper::Machinist::DataMapperExtentions
- Included in:
- Resource::ClassMethods
- Defined in:
- lib/dm-machinist/machinist.rb
Defined Under Namespace
Classes: Lathe
Instance Method Summary collapse
- #blueprint(&blueprint) ⇒ Object
- #make(attributes = {}) ⇒ Object
- #make_unsaved(attributes = {}) ⇒ Object
Instance Method Details
#blueprint(&blueprint) ⇒ Object
19 20 21 |
# File 'lib/dm-machinist/machinist.rb', line 19 def blueprint(&blueprint) @blueprint = blueprint end |
#make(attributes = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dm-machinist/machinist.rb', line 23 def make(attributes = {}) @saved = false @reloaded = false raise "No blueprint for class #{self}" if @blueprint.nil? lathe = Lathe.new(self, attributes) lathe.instance_eval(&@blueprint) unless Machinist.nerfed? unless lathe.object.save raise "Error: #{lathe.object.errors.inspect}" end lathe.object.reload end returning(lathe.object) do |object| yield object if block_given? end end |
#make_unsaved(attributes = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/dm-machinist/machinist.rb', line 40 def make_unsaved(attributes = {}) returning(Machinist.with_save_nerfed { make(attributes) }) do |object| yield object if block_given? end end |