Module: ActAsReleasable::InstanceMethods
- Defined in:
- lib/act_as_releasable.rb
Instance Method Summary collapse
Instance Method Details
#generate_new_candidate ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/act_as_releasable.rb', line 52 def generate_new_candidate if valid? # Destroying prototype data releasable_candidate.destroy if releasable_candidate.present? releasable_candidate_items.destroy_all # Creating new prototype data create_releasable_candidate! :candidate_attributes => attributes self.releasable_collections.each do |collection| send(collection).each do |collection_item| unless collection_item.marked_for_destruction? releasable_candidate_items.create! ({:candidate_attributes => collection_item.attributes, :collection_name => collection}) end end end end end |
#release_candidate ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/act_as_releasable.rb', line 40 def release_candidate clone.tap do self.releasable_collections.each do |collection| send(collection).clear end self.attributes = releasable_candidate.try(:candidate_attributes) || {} releasable_candidate_items.each do |candidate_item| send(candidate_item.collection_name).build candidate_item.candidate_attributes end end end |
#release_version! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/act_as_releasable.rb', line 21 def release_version! # Clean-up of the official record self.releasable_collections.each do |collection| send(collection).destroy_all end # Updating attributes self.attributes = releasable_candidate.candidate_attributes releasable_candidate_items.each do |candidate_item| send(candidate_item.collection_name).build candidate_item.candidate_attributes end # Destroying prototype data releasable_candidate.destroy if releasable_candidate.present? releasable_candidate_items.destroy_all save! end |