act_as_releasable 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/act_as_releasable.rb +29 -23
- data/lib/act_as_releasable/version.rb +1 -1
- metadata +1 -1
data/lib/act_as_releasable.rb
CHANGED
@@ -19,22 +19,24 @@ module ActAsReleasable
|
|
19
19
|
|
20
20
|
module InstanceMethods
|
21
21
|
def release_version!
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
34
|
+
# Destroying prototype data
|
35
|
+
releasable_candidate.destroy if releasable_candidate.present?
|
36
|
+
releasable_candidate_items.destroy_all
|
36
37
|
|
37
|
-
|
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
|
-
|
55
|
-
releasable_candidate.destroy if releasable_candidate.present?
|
56
|
-
releasable_candidate_items.destroy_all
|
56
|
+
ActiveRecord::Base.transaction do
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
71
|
+
|
72
|
+
end # transaction
|
67
73
|
end
|
68
74
|
end
|
69
75
|
|