purgatory 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.markdown +9 -4
- data/VERSION +1 -1
- data/lib/purgatory/purgatory.rb +11 -4
- data/lib/purgatory/purgatory_module.rb +2 -1
- data/purgatory.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDk0ZTBiMmNiNjlmMWUyODRjNTc0OWZjNjE5YTAxZDE0YTI1YjExYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWZjODBlNzQ0MDNmYWI2NmE1MTEyZWQwNjBlYzEwYTcwMzgxNTljZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGFhNDljZmM4YjU0YWZiNTllNjgwZDcyMjhlMGUwZWIzZDRkYzMzMjk1ZWM5
|
10
|
+
YTkwOWVkNjg4MjViNzFhZGE0MzM0ODdhNGQ4YTEwYmQwMDgxNWRlMmMzMGQ2
|
11
|
+
YzllMzlhYmQ1MTAzMmNjY2M0NTkyMjg0NjNhZGVjNWVhZTI1YmI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGJmNDZhNjNhMWQ2ZTdmMGYwMzAyNDMyZjQ3NjFiY2U1MThhYzNiNzYzM2Vl
|
14
|
+
MzdjYThkZGUyNGVjN2JlYmQ0M2M3MzU0MGJmNDMxYTVmYzQ0YjFiYmQyMWNk
|
15
|
+
MjY2MzBjYjNhZWZkNTk3ZTlkNzc2MGY1NTg3YzI3ZTY0MjBiMjI=
|
data/README.markdown
CHANGED
@@ -16,16 +16,21 @@ To enable Purgatory functionality in a class, add the following line to the clas
|
|
16
16
|
|
17
17
|
use_purgatory
|
18
18
|
|
19
|
-
To put your changes to an ActiveRecord class into Purgatory, simply make your changes and then call the purgatory! method
|
19
|
+
To put your changes to an ActiveRecord class into Purgatory, simply make your changes and then call the purgatory! method. You can pass in the requesting user as an optional parameter
|
20
20
|
|
21
21
|
item = Item.find(10)
|
22
22
|
item.price = 200
|
23
|
-
item.purgatory!(current_user)
|
23
|
+
purgatory = item.purgatory!(current_user) # returns the newly created purgatory or nil if the item is changes are invalid
|
24
24
|
|
25
|
-
To apply the changes, simply call the approve! method on the associated Pergatory instance
|
25
|
+
To apply the changes, simply call the approve! method on the associated Pergatory instance. You can pass in the approving user as an optional parameter
|
26
26
|
|
27
27
|
purgatory = item.purgatories.last
|
28
|
-
purgatory.approve!(current_user)
|
28
|
+
purgatory.approve!(current_user) # returns a boolean for whether or not this succeeded
|
29
|
+
|
30
|
+
You can also put the creation of a new object into Purgatory
|
31
|
+
|
32
|
+
item = Item.new price: 100
|
33
|
+
purgatory = item.purgatory!
|
29
34
|
|
30
35
|
The following are some attributes of a purgatory:
|
31
36
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
data/lib/purgatory/purgatory.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
class Purgatory < ActiveRecord::Base
|
2
2
|
attr_accessible :requester, :soul
|
3
3
|
|
4
|
-
belongs_to :soul, polymorphic: true
|
4
|
+
belongs_to :soul, polymorphic: true, autosave: false
|
5
5
|
belongs_to :requester, class_name: 'User'
|
6
6
|
belongs_to :approver, class_name: 'User'
|
7
7
|
before_create :store_changes
|
8
8
|
|
9
|
-
validates :
|
9
|
+
validates :soul_type, presence: true
|
10
10
|
|
11
11
|
scope :pending, conditions: { approved_at: nil }
|
12
12
|
scope :approved, conditions: ["approved_at IS NOT NULL"]
|
@@ -23,14 +23,21 @@ class Purgatory < ActiveRecord::Base
|
|
23
23
|
ActiveSupport::JSON.decode(changes_json)
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
26
|
+
def soul
|
27
|
+
super || soul_type.constantize.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def approve!(approver = nil)
|
31
|
+
return false if approved?
|
28
32
|
changes = changes_hash
|
33
|
+
|
29
34
|
if soul.update_attributes(changes.update(changes){|k,v| v.last}, without_protection: true)
|
30
35
|
self.approver = approver
|
31
36
|
self.approved_at = Time.now
|
32
37
|
save
|
38
|
+
return true
|
33
39
|
end
|
40
|
+
false
|
34
41
|
end
|
35
42
|
|
36
43
|
private
|
data/purgatory.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: purgatory
|
5
|
+
# stub: purgatory 2.0.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "purgatory"
|
9
|
-
s.version = "
|
9
|
+
s.version = "2.0.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Elan Dubrofsky"]
|