Module: ActAsReleasable::InstanceMethods
- Defined in:
- lib/act_as_releasable.rb
Instance Method Summary collapse
- #generate_new_candidate ⇒ Object
- #has_changes_to_be_approved? ⇒ Boolean
- #release_candidate ⇒ Object
- #release_version! ⇒ Object
Instance Method Details
#generate_new_candidate ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/act_as_releasable.rb', line 51 def generate_new_candidate if valid? ActiveRecord::Base.transaction do # 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 # transaction end end |
#has_changes_to_be_approved? ⇒ Boolean
73 74 75 |
# File 'lib/act_as_releasable.rb', line 73 def has_changes_to_be_approved? releasable_candidate.present? || !releasable_candidate_items.empty? end |
#release_candidate ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/act_as_releasable.rb', line 42 def release_candidate self.class.new.tap do |clone| clone.attributes = releasable_candidate.try(:candidate_attributes) || {} releasable_candidate_items.each do |candidate_item| clone.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 39 40 |
# File 'lib/act_as_releasable.rb', line 21 def release_version! ActiveRecord::Base.transaction do # 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 end |