review_and_approve 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # ReviewAndApprove
2
+
3
+ Add functionality in a content based app to explicitly review and approve all data changes before they are visible to end users.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'review_and_approve'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install review_and_approve
18
+
19
+ ## Usage
20
+
21
+ call `review_and_approve` in an ActiveRecord class
22
+
23
+ ```ruby
24
+ class Product < ActiveRecord::Base
25
+ review_and_approve :by => [:as_json, :to_json] #defaults to :by => [:as_json] - list of methods whose output will be cached for delta comparisons
26
+ end
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require ./delta
3
+ */
@@ -0,0 +1,49 @@
1
+ .review_and_approve table tr td{
2
+ border: 1px solid black;
3
+ }
4
+
5
+
6
+ .review_and_approve
7
+ {
8
+ font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
9
+ font-size: 12px;
10
+ margin: 45px;
11
+ width: 480px;
12
+ text-align: left;
13
+ border-collapse: collapse;
14
+ }
15
+ .review_and_approve thead th.rounded-company
16
+ {
17
+ background: #b9c9fe url('table-images/left.png') left -1px no-repeat;
18
+ }
19
+ .review_and_approve thead th.rounded-q4
20
+ {
21
+ background: #b9c9fe url('table-images/right.png') right -1px no-repeat;
22
+ }
23
+ .review_and_approve th
24
+ {
25
+ padding: 8px;
26
+ font-weight: normal;
27
+ font-size: 13px;
28
+ color: #039;
29
+ background: #b9c9fe;
30
+ }
31
+ .review_and_approve td
32
+ {
33
+ padding: 8px;
34
+ background: #e8edff;
35
+ border-top: 1px solid #fff;
36
+ color: #669;
37
+ }
38
+ .review_and_approve tfoot td.rounded-foot-left
39
+ {
40
+ background: #e8edff url('table-images/botleft.png') left bottom no-repeat;
41
+ }
42
+ .review_and_approve tfoot td.rounded-foot-right
43
+ {
44
+ background: #e8edff url('table-images/botright.png') right bottom no-repeat;
45
+ }
46
+ .review_and_approve tbody tr:hover td
47
+ {
48
+ background: #d0dafd;
49
+ }
@@ -0,0 +1,26 @@
1
+ <% published ||= {} %>
2
+ <% diff_keys = published.diff(current).keys %>
3
+ <div class="review_and_approve">
4
+ <% if diff_keys.count > 0 %>
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th scope="col" class="rounded-company">Field Name</th>
9
+ <th scope="col" class="rounded-q1">Published Value</th>
10
+ <th scope="col" class="rounded-q4">Current Value</th>
11
+ </tr>
12
+ </thead>
13
+ <% published.diff(current).keys.each do |key| %>
14
+ <tbody>
15
+ <tr>
16
+ <td><%= key %></td>
17
+ <td><%= published[key] || "<BLANK>" %></td>
18
+ <td><%= current[key] || "<BLANK>" %></td>
19
+ </tr>
20
+ </tbody>
21
+ <% end %>
22
+ </table>
23
+ <% else %>
24
+ Latest version is published
25
+ <% end %>
26
+ </div>
@@ -0,0 +1,4 @@
1
+ module ReviewAndApprove
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,42 @@
1
+ module ReviewAndApprove
2
+ module ModelAdditions
3
+ class ModelValidator < ActiveModel::Validator
4
+ def validate(record)
5
+ if Thread.current[:reviewAndApprove_current_ability].cannot?(:publish, record) and record.published
6
+ record.errors[:published] << "can not be marked as true by this user"
7
+ end
8
+ end
9
+ end
10
+
11
+ def review_and_approve(*args)
12
+ methods = [:as_json]
13
+ args.each do |arg|
14
+ if arg.is_a? Hash
15
+ if arg[:by].present?
16
+ methods = arg[:by]
17
+ end
18
+ end
19
+ end
20
+ before_save do
21
+ if Thread.current[:reviewAndApprove_current_ability].cannot? :publish, self
22
+ self.published = false
23
+ end
24
+ true
25
+ end
26
+
27
+ after_save do
28
+ if self.published
29
+ methods.each do |method|
30
+ Rails.cache.write("ReviewAndApprove_#{self.class.name}_#{self.id}_#{method}", self.send(method))
31
+ end
32
+ end
33
+ end
34
+
35
+ send(:define_method, :published_version) do |method_name|
36
+ Rails.cache.read("ReviewAndApprove_#{self.class.name}_#{self.id}_#{method_name}")
37
+ end
38
+
39
+ send(:validates_with, ReviewAndApprove::ModelAdditions::ModelValidator)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ module ReviewAndApprove
2
+ class Railtie < Rails::Railtie
3
+ initializer 'review_and_approve.model_additions' do
4
+ ActiveSupport.on_load(:active_record) do
5
+ extend ModelAdditions
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ReviewAndApprove
2
+ VERSION = "0.0.1.alpha"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "review_and_approve/version"
2
+ require "review_and_approve/engine"
3
+ require "review_and_approve/model_additions"
4
+ require "review_and_approve/railtie" if defined? Rails
5
+
6
+ module ReviewAndApprove
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: review_and_approve
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 6
5
+ version: 0.0.1.alpha
6
+ platform: ruby
7
+ authors:
8
+ - Paramveer Singh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2013-05-15 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "2.0"
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.8.7
35
+ type: :development
36
+ version_requirements: *id002
37
+ description: Adds Review and Approval functionality for content sites.
38
+ email:
39
+ - paramveer.singh@hikeezee.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - app/assets/stylesheets/review_and_approve/application.css
48
+ - app/assets/stylesheets/review_and_approve/delta.css
49
+ - app/views/review_and_approve/_delta.html.erb
50
+ - lib/review_and_approve/engine.rb
51
+ - lib/review_and_approve/model_additions.rb
52
+ - lib/review_and_approve/railtie.rb
53
+ - lib/review_and_approve/version.rb
54
+ - lib/review_and_approve.rb
55
+ - Rakefile
56
+ - README.md
57
+ homepage: ""
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">"
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.1
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.25
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Adds Review and Approval functionality for content sites.
84
+ test_files: []
85
+