purgatory 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGU4MWYzYTMwMDA2MzBjN2U1ZDc0ZDMzMGRmMTA5YTE3ZTE0Mjg4Mw==
5
+ data.tar.gz: !binary |-
6
+ YmViZGNmYTUxNjQ0MjdhYmVkZGZkMWFlNDI3MmRiNzIzODZkMzI4Zg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Zjc2NWM4NThhNjZiMzM4NmQ3ODFlYjAxYjRjODY2MjljYzBhYzE2NzQxMGY2
10
+ ZmEzNWU3Mjg2OTkzMjNjOWRlMDJkOTdjZGQ5MWE5NTNmMDdmYTBiYjEwZjBl
11
+ ZGY2M2NkMjc0OTIwOWU1ZGZkYzZlOGJhMzVmNjQxZTNmMjc3Y2I=
12
+ data.tar.gz: !binary |-
13
+ NjhjMjQ2MzQ0MzRhYmI1NzVhMzZkZDc5OWEwODk3ZTcwNDM4YTM2MDMzM2Y3
14
+ NzI2ZmI4NWM4NzM4NDM0MDgyZGU2MGIyOWE4YjBkN2YzOTRjYmFjZjZmYTU3
15
+ NzJhMTlhYTdlNDdiYzYyZmNhZWM0MjY1MGNjOTI2YjZlYTIyYmQ=
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 1.8.7"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.1)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.14)
12
+ builder (3.2.2)
13
+ faraday (0.8.8)
14
+ multipart-post (~> 1.2.0)
15
+ git (1.2.6)
16
+ github_api (0.10.1)
17
+ addressable
18
+ faraday (~> 0.8.1)
19
+ hashie (>= 1.2)
20
+ multi_json (~> 1.4)
21
+ nokogiri (~> 1.5.2)
22
+ oauth2
23
+ hashie (2.0.5)
24
+ highline (1.6.20)
25
+ httpauth (0.2.0)
26
+ i18n (0.6.5)
27
+ jeweler (1.8.8)
28
+ builder
29
+ bundler (~> 1.0)
30
+ git (>= 1.2.5)
31
+ github_api (= 0.10.1)
32
+ highline (>= 1.6.15)
33
+ nokogiri (= 1.5.10)
34
+ rake
35
+ rdoc
36
+ json (1.8.1)
37
+ jwt (0.1.8)
38
+ multi_json (>= 1.5)
39
+ minitest (4.7.5)
40
+ multi_json (1.8.2)
41
+ multi_xml (0.5.5)
42
+ multipart-post (1.2.0)
43
+ nokogiri (1.5.10)
44
+ oauth2 (0.9.2)
45
+ faraday (~> 0.8)
46
+ httpauth (~> 0.2)
47
+ jwt (~> 0.1.4)
48
+ multi_json (~> 1.0)
49
+ multi_xml (~> 0.5)
50
+ rack (~> 1.2)
51
+ rack (1.5.2)
52
+ rake (10.1.0)
53
+ rdoc (3.12.2)
54
+ json (~> 1.4)
55
+ shoulda (3.5.0)
56
+ shoulda-context (~> 1.0, >= 1.0.1)
57
+ shoulda-matchers (>= 1.4.1, < 3.0)
58
+ shoulda-context (1.1.5)
59
+ shoulda-matchers (2.4.0)
60
+ activesupport (>= 3.0.0)
61
+ thread_safe (0.1.3)
62
+ atomic
63
+ tzinfo (0.3.38)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 1.0)
70
+ jeweler (~> 1.8.7)
71
+ rdoc (~> 3.12)
72
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Elan Dubrofsky
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,44 @@
1
+ # Purgatory
2
+
3
+ Purgatory allows you to put changes to an ActiveRecord model into purgatory until they are approved
4
+
5
+ ## How to Use
6
+
7
+ First run the generator the create the required migrations:
8
+
9
+ $ rails generate purgatory
10
+
11
+ Then migrate the database:
12
+
13
+ $ rake db:migrate
14
+
15
+ To enable Purgatory functionality in a class, add the following line to the class:
16
+
17
+ use_purgatory
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
20
+
21
+ item = Item.find(10)
22
+ item.price = 200
23
+ item.purgatory!(current_user)
24
+
25
+ To apply the changes, simply call the approve! method on the associated Pergatory instance, passing in the approving user as a parameter
26
+
27
+ purgatory = Purgatory.where(soul_id: 10, soul_type: 'Item')
28
+ purgatory.approve!(current_user)
29
+
30
+ ## Contributing to Purgatory
31
+
32
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
33
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
34
+ * Fork the project.
35
+ * Start a feature/bugfix branch.
36
+ * Commit and push until you are happy with your contribution.
37
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
38
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
39
+
40
+ ## Copyright
41
+
42
+ Copyright (c) 2013 Elan Dubrofsky. See LICENSE.txt for
43
+ further details.
44
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "purgatory"
18
+ gem.homepage = "http://github.com/dubroe/purgatory"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Allow changes to a model to be put in purgatory until they are approved}
21
+ gem.description = %Q{Put your model changes in purgatory and allow them to remain lost souls until they are approved}
22
+ gem.email = "elan.dubrofsky@gmail.com"
23
+ gem.authors = ["Elan Dubrofsky"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "purgatory #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'purgatory'
@@ -0,0 +1,22 @@
1
+ # Requires
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ class PurgatoryGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ def self.source_root
8
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ def self.next_migration_number(dirname)
12
+ if ActiveRecord::Base.timestamped_migrations
13
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
14
+ else
15
+ "%.3d" % (current_migration_number(dirname) + 1)
16
+ end
17
+ end
18
+
19
+ def create_migration_file
20
+ migration_template 'create_purgatories.rb', 'db/migrate/create_purgatories.rb'
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePurgatories < ActiveRecord::Migration
2
+ def change
3
+ create_table :purgatories do |t|
4
+ t.integer :soul_id
5
+ t.string :soul_type
6
+ t.integer :requester_id
7
+ t.integer :approver_id
8
+ t.datetime :approved_at
9
+ t.string :changes_json
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ class Purgatory < ActiveRecord::Base
2
+ attr_accessible :requester, :soul
3
+
4
+ belongs_to :soul, polymorphic: true
5
+ belongs_to :requester, class_name: 'User'
6
+ belongs_to :approver, class_name: 'User'
7
+ before_create :store_changes
8
+
9
+ validates :soul, :requester, presence: true
10
+
11
+ def changes_hash
12
+ ActiveSupport::JSON.decode(changes_json)
13
+ end
14
+
15
+ def approve!(approver)
16
+ return if approved_at.present?
17
+ changes = changes_hash
18
+ if soul.update_attributes(changes.update(changes){|k,v| v.last}, without_protection: true)
19
+ self.approver = approver
20
+ self.approved_at = Time.now
21
+ save
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def store_changes
28
+ self.changes_json = ActiveSupport::JSON.encode(soul.changes)
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module PurgatoryModule
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def use_purgatory
6
+ self.has_many :purgatories, as: :soul
7
+ end
8
+ end
9
+
10
+ def purgatory!(requester)
11
+ Purgatory.create soul: self, requester: requester
12
+ end
13
+ end
data/lib/purgatory.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'purgatory/purgatory'
2
+ require 'purgatory/purgatory_module'
3
+ ActiveRecord::Base.send(:include, PurgatoryModule)
data/purgatory.gemspec ADDED
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: purgatory 0.2.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "purgatory"
9
+ s.version = "0.2.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Elan Dubrofsky"]
13
+ s.date = "2013-11-21"
14
+ s.description = "Put your model changes in purgatory and allow them to remain lost souls until they are approved"
15
+ s.email = "elan.dubrofsky@gmail.com"
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.markdown"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.markdown",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "init.rb",
29
+ "lib/generators/purgatory/purgatory_generator.rb",
30
+ "lib/generators/purgatory/templates/create_purgatories.rb",
31
+ "lib/purgatory.rb",
32
+ "lib/purgatory/purgatory.rb",
33
+ "lib/purgatory/purgatory_module.rb",
34
+ "purgatory.gemspec",
35
+ "test/helper.rb",
36
+ "test/test_purgatory.rb"
37
+ ]
38
+ s.homepage = "http://github.com/dubroe/purgatory"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "2.1.10"
42
+ s.summary = "Allow changes to a model to be put in purgatory until they are approved"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 4
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
52
+ else
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
63
+ end
64
+ end
65
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'purgatory'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestPurgatory < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: purgatory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Elan Dubrofsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoulda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.7
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.7
69
+ description: Put your model changes in purgatory and allow them to remain lost souls
70
+ until they are approved
71
+ email: elan.dubrofsky@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - LICENSE.txt
76
+ - README.markdown
77
+ files:
78
+ - .document
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.markdown
83
+ - Rakefile
84
+ - VERSION
85
+ - init.rb
86
+ - lib/generators/purgatory/purgatory_generator.rb
87
+ - lib/generators/purgatory/templates/create_purgatories.rb
88
+ - lib/purgatory.rb
89
+ - lib/purgatory/purgatory.rb
90
+ - lib/purgatory/purgatory_module.rb
91
+ - purgatory.gemspec
92
+ - test/helper.rb
93
+ - test/test_purgatory.rb
94
+ homepage: http://github.com/dubroe/purgatory
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.1.10
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Allow changes to a model to be put in purgatory until they are approved
118
+ test_files: []