Module: ActAsReleasable::InstanceMethods

Defined in:
lib/act_as_releasable.rb

Instance Method Summary collapse

Instance Method Details

#generate_new_candidateObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/act_as_releasable.rb', line 54

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

Returns:

  • (Boolean)


76
77
78
# File 'lib/act_as_releasable.rb', line 76

def has_changes_to_be_approved?
  releasable_candidate.present? || !releasable_candidate_items.empty?
end

#release_candidateObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/act_as_releasable.rb', line 42

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
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