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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjBmNmUyZGQ4NDBjYmI5OWQyNTg1ZmIzNjZkYzdlOWFjZWU2OTNjZg==
4
+ MDk0ZTBiMmNiNjlmMWUyODRjNTc0OWZjNjE5YTAxZDE0YTI1YjExYQ==
5
5
  data.tar.gz: !binary |-
6
- ZjQ4NDFlZTk3N2Y4NDY2ZjYwMjI0ZTM0YTM0MTcyNWM1Y2Y4ZWVlMg==
6
+ MWZjODBlNzQ0MDNmYWI2NmE1MTEyZWQwNjBlYzEwYTcwMzgxNTljZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDMzNGY5MGZiODc2N2JmZjNiYmNmMGJlZjBhMDlmZmEzYzRlM2FjNjc2YWZj
10
- NDM2MmM5OTZkZmZlYjMxMDllNTU4NDQ5ZjM5MmEwMTY2NTBiYTFhZTk2Y2Q4
11
- NjliMDQ4NjE0ZjQ0NmE2ZDgzNWFkMzdjNmQ3ZTQ0MmYzYWI1OTA=
9
+ OGFhNDljZmM4YjU0YWZiNTllNjgwZDcyMjhlMGUwZWIzZDRkYzMzMjk1ZWM5
10
+ YTkwOWVkNjg4MjViNzFhZGE0MzM0ODdhNGQ4YTEwYmQwMDgxNWRlMmMzMGQ2
11
+ YzllMzlhYmQ1MTAzMmNjY2M0NTkyMjg0NjNhZGVjNWVhZTI1YmI=
12
12
  data.tar.gz: !binary |-
13
- NTFkMGQ5MDczMWU4NTNjOTFkOWU4ZmM0ZDgyZjI3YjQ0ZmE2ZTY5MGJkYWZh
14
- Y2I1OWI2NTVmMGMzMzliN2Y1OTUxM2RhZTliODJhNTBkNjM4ZGZiZTY4ZjUy
15
- ODg5ZDNkNzM4YTViMzEwNGYzZDg1YTcwMmRjZmU5ZDQwNzY2ZjA=
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, passing the requesting user as a parameter
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, passing in the approving user as a parameter
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.1.0
1
+ 2.0.0
@@ -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 :soul, :requester, presence: true
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 approve!(approver)
27
- return if approved_at.present?
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
@@ -7,7 +7,8 @@ module PurgatoryModule
7
7
  end
8
8
  end
9
9
 
10
- def purgatory!(requester)
10
+ def purgatory!(requester = nil)
11
+ return nil if self.invalid?
11
12
  Purgatory.create soul: self, requester: requester
12
13
  end
13
14
  end
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 1.1.0 ruby lib
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 = "1.1.0"
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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purgatory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elan Dubrofsky