act_as_releasable 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,22 +19,24 @@ module ActAsReleasable
19
19
 
20
20
  module InstanceMethods
21
21
  def release_version!
22
- # Clean-up of the official record
23
- self.releasable_collections.each do |collection|
24
- send(collection).destroy_all
25
- end
22
+ ActiveRecord::Base.transaction do
23
+ # Clean-up of the official record
24
+ self.releasable_collections.each do |collection|
25
+ send(collection).destroy_all
26
+ end
26
27
 
27
- # Updating attributes
28
- self.attributes = releasable_candidate.candidate_attributes
29
- releasable_candidate_items.each do |candidate_item|
30
- send(candidate_item.collection_name).build candidate_item.candidate_attributes
31
- end
28
+ # Updating attributes
29
+ self.attributes = (releasable_candidate.candidate_attributes || {})
30
+ releasable_candidate_items.each do |candidate_item|
31
+ send(candidate_item.collection_name).build candidate_item.candidate_attributes
32
+ end
32
33
 
33
- # Destroying prototype data
34
- releasable_candidate.destroy if releasable_candidate.present?
35
- releasable_candidate_items.destroy_all
34
+ # Destroying prototype data
35
+ releasable_candidate.destroy if releasable_candidate.present?
36
+ releasable_candidate_items.destroy_all
36
37
 
37
- save!
38
+ save!
39
+ end
38
40
  end
39
41
 
40
42
  def release_candidate
@@ -51,19 +53,23 @@ module ActAsReleasable
51
53
 
52
54
  def generate_new_candidate
53
55
  if valid?
54
- # Destroying prototype data
55
- releasable_candidate.destroy if releasable_candidate.present?
56
- releasable_candidate_items.destroy_all
56
+ ActiveRecord::Base.transaction do
57
57
 
58
- # Creating new prototype data
59
- create_releasable_candidate! :candidate_attributes => attributes
60
- self.releasable_collections.each do |collection|
61
- send(collection).each do |collection_item|
62
- unless collection_item.marked_for_destruction?
63
- releasable_candidate_items.create! ({:candidate_attributes => collection_item.attributes, :collection_name => collection})
58
+ # Destroying prototype data
59
+ releasable_candidate.destroy if releasable_candidate.present?
60
+ releasable_candidate_items.destroy_all
61
+
62
+ # Creating new prototype data
63
+ create_releasable_candidate! :candidate_attributes => attributes
64
+ self.releasable_collections.each do |collection|
65
+ send(collection).each do |collection_item|
66
+ unless collection_item.marked_for_destruction?
67
+ releasable_candidate_items.create! ({:candidate_attributes => collection_item.attributes, :collection_name => collection})
68
+ end
64
69
  end
65
70
  end
66
- end
71
+
72
+ end # transaction
67
73
  end
68
74
  end
69
75
 
@@ -1,3 +1,3 @@
1
1
  module ActAsReleasable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: act_as_releasable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: