Module: Machinist::Extensions::ClassMethods
- Defined in:
- lib/machinist.rb
Instance Method Summary collapse
- #blueprint(&blueprint) ⇒ Object
- #make(attributes = {}, &block) ⇒ Object
- #make_unsaved(attributes = {}) ⇒ Object
Instance Method Details
#blueprint(&blueprint) ⇒ Object
33 34 35 36 |
# File 'lib/machinist.rb', line 33 def blueprint(&blueprint) @blueprint = blueprint @machinist_adapter = Machinist.adapter_for(self) end |
#make(attributes = {}, &block) ⇒ Object
38 39 40 41 |
# File 'lib/machinist.rb', line 38 def make(attributes = {}, &block) obj = make_unsaved(attributes.merge(:_save_ => true), &block) @machinist_adapter.save(obj) end |
#make_unsaved(attributes = {}) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/machinist.rb', line 43 def make_unsaved(attributes = {}) raise "No blueprint for class #{self}" if @blueprint.nil? lathe = Lathe.new(self, attributes) lathe.instance_eval(&@blueprint) returning(lathe.object) do |object| yield object if block_given? end end |