review_and_approve 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -61,13 +61,12 @@ A method called `published_version` is defined on the model that provides access
61
61
  # Given two hashes (before/after), this will render the changes in a table
62
62
 
63
63
  #styling the differences
64
- Check out delta.css in the gem and override the styles in your application
64
+ Include review_and_approve/application in your application.css or
65
+ check out delta.css in the gem and override the styles in your application
65
66
  ```
66
67
 
67
68
  ## Limitations
68
69
  * only certified on Rails 3.1, ruby 1.9.2
69
- * Will use Rails.cache to store the output of methods provided to review_and_approve. We currently assume that the cache has infinite space -i.e. the cached value is never lost
70
- - possibly use the database in future for storing cached values
71
70
  * Currently depends on the application to call attr_accessible
72
71
 
73
72
 
@@ -10,7 +10,7 @@
10
10
  <th scope="col" class="rounded-q4">Current Value</th>
11
11
  </tr>
12
12
  </thead>
13
- <% published.diff(current).keys.each do |key| %>
13
+ <% diff_keys.each do |key| %>
14
14
  <tbody>
15
15
  <tr>
16
16
  <td><%= key %></td>
@@ -23,4 +23,4 @@
23
23
  <% else %>
24
24
  Latest version is published
25
25
  <% end %>
26
- </div>
26
+ </div>
@@ -0,0 +1,24 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module ReviewAndApprove
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ desc "add the migrations"
9
+
10
+ def self.next_migration_number(path)
11
+ unless @prev_migration_nr
12
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
13
+ else
14
+ @prev_migration_nr += 1
15
+ end
16
+ @prev_migration_nr.to_s
17
+ end
18
+
19
+ def copy_migrations
20
+ migration_template "create_cache_records.rb", "db/migrate/create_cache_records.rb"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ class CreateCacheRecords < ActiveRecord::Migration
2
+ def change
3
+ create_table :cache_records do |t|
4
+ t.string :key
5
+ t.text :cache_data
6
+ t.timestamps
7
+ end
8
+
9
+ add_index :cache_records, :key
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ class CacheRecord < ActiveRecord::Base
2
+ serialize :cache_data
3
+ end
@@ -24,13 +24,22 @@ module ReviewAndApprove
24
24
  # define the field as an attribute on the model
25
25
  attr_accessor field
26
26
 
27
- after_save do
28
- published = self.send(field)
27
+ # identifier on the class that it has been set up with review_and_approve
28
+ send(:define_singleton_method, :_using_rev_app?) do
29
+ true
30
+ end
31
+
32
+ after_save :review_and_approve_after_save_callback
33
+
34
+ send(:define_method, :review_and_approve_after_save_callback) do |publish = false|
35
+ published = self.send(field) || publish
29
36
  #If we are publishing the record
30
37
  if published and (published==true or published=="true" or self.send(field).to_i>0 rescue false) #in case the field gets set to "0" and "1"
31
38
  methods.each do |method|
32
39
  # Refresh all caches
33
- Rails.cache.write(key_proc.call(self, method), self.send(method))
40
+ CacheRecord.find_or_initialize_by_key(key_proc.call(self, method)).tap do |cr|
41
+ cr.cache_data = self.send(method)
42
+ end.save
34
43
  end
35
44
  end
36
45
 
@@ -38,7 +47,7 @@ module ReviewAndApprove
38
47
  end
39
48
 
40
49
  send(:define_method, :published_version) do |method_name|
41
- Rails.cache.read(key_proc.call(self, method_name))
50
+ CacheRecord.find_by_key(key_proc.call(self, method_name)).cache_data
42
51
  end
43
52
 
44
53
  send(:define_method, :mass_assignment_authorizer) do |role = :default|
@@ -1,3 +1,3 @@
1
1
  module ReviewAndApprove
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -3,6 +3,8 @@ require "review_and_approve/engine" if defined? Rails
3
3
  require "review_and_approve/model_additions"
4
4
  require "review_and_approve/controller_additions"
5
5
  require "review_and_approve/railtie" if defined? Rails
6
+ require 'active_record'
7
+ require "review_and_approve/cache_record"
6
8
 
7
9
  module ReviewAndApprove
8
10
 
@@ -0,0 +1,10 @@
1
+ desc 'Create caches for existing data'
2
+ namespace :review_and_approve do
3
+ task :create_caches => :environment do
4
+ ActiveRecord::Base.subclasses.select{|m| model._using_rev_app? rescue false}.each do |model|
5
+ model.find_each do |obj|
6
+ obj.review_and_approve_after_save_callback(true)
7
+ end
8
+ end
9
+ end
10
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: review_and_approve
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paramveer Singh
@@ -10,11 +10,10 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-05-18 00:00:00 Z
13
+ date: 2013-05-20 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- prerelease: false
18
17
  requirement: &id001 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
@@ -22,10 +21,10 @@ dependencies:
22
21
  - !ruby/object:Gem::Version
23
22
  version: "2.0"
24
23
  type: :development
24
+ prerelease: false
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rake
28
- prerelease: false
29
28
  requirement: &id002 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
@@ -33,21 +32,21 @@ dependencies:
33
32
  - !ruby/object:Gem::Version
34
33
  version: "0"
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: supermodel
39
- prerelease: false
40
39
  requirement: &id003 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
42
  - - ">="
44
43
  - !ruby/object:Gem::Version
45
44
  version: "0"
46
- type: :runtime
45
+ type: :development
46
+ prerelease: false
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: mocha
50
- prerelease: false
51
50
  requirement: &id004 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
@@ -55,21 +54,21 @@ dependencies:
55
54
  - !ruby/object:Gem::Version
56
55
  version: "0"
57
56
  type: :development
57
+ prerelease: false
58
58
  version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
60
- name: rails
61
- prerelease: false
60
+ name: debugger
62
61
  requirement: &id005 !ruby/object:Gem::Requirement
63
62
  none: false
64
63
  requirements:
65
64
  - - ">="
66
65
  - !ruby/object:Gem::Version
67
66
  version: "0"
68
- type: :runtime
67
+ type: :development
68
+ prerelease: false
69
69
  version_requirements: *id005
70
70
  - !ruby/object:Gem::Dependency
71
- name: cancan
72
- prerelease: false
71
+ name: rails
73
72
  requirement: &id006 !ruby/object:Gem::Requirement
74
73
  none: false
75
74
  requirements:
@@ -77,18 +76,30 @@ dependencies:
77
76
  - !ruby/object:Gem::Version
78
77
  version: "0"
79
78
  type: :runtime
79
+ prerelease: false
80
80
  version_requirements: *id006
81
81
  - !ruby/object:Gem::Dependency
82
- name: debugger
83
- prerelease: false
82
+ name: cancan
84
83
  requirement: &id007 !ruby/object:Gem::Requirement
85
84
  none: false
86
85
  requirements:
87
86
  - - ">="
88
87
  - !ruby/object:Gem::Version
89
88
  version: "0"
90
- type: :development
89
+ type: :runtime
90
+ prerelease: false
91
91
  version_requirements: *id007
92
+ - !ruby/object:Gem::Dependency
93
+ name: activerecord
94
+ requirement: &id008 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ type: :runtime
101
+ prerelease: false
102
+ version_requirements: *id008
92
103
  description: Adds Review and Approval functionality for content sites.
93
104
  email:
94
105
  - paramveer.singh@hikeezee.com
@@ -102,12 +113,16 @@ files:
102
113
  - app/assets/stylesheets/review_and_approve/application.css
103
114
  - app/assets/stylesheets/review_and_approve/delta.css
104
115
  - app/views/review_and_approve/_delta.html.erb
116
+ - lib/generators/review_and_approve/install/install_generator.rb
117
+ - lib/generators/review_and_approve/install/templates/create_cache_records.rb
118
+ - lib/review_and_approve/cache_record.rb
105
119
  - lib/review_and_approve/controller_additions.rb
106
120
  - lib/review_and_approve/engine.rb
107
121
  - lib/review_and_approve/model_additions.rb
108
122
  - lib/review_and_approve/railtie.rb
109
123
  - lib/review_and_approve/version.rb
110
124
  - lib/review_and_approve.rb
125
+ - lib/tasks/review_and_approve.rake
111
126
  - Rakefile
112
127
  - README.md
113
128
  homepage: ""
@@ -123,12 +138,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
138
  requirements:
124
139
  - - ">="
125
140
  - !ruby/object:Gem::Version
141
+ hash: -927429969750751341
142
+ segments:
143
+ - 0
126
144
  version: "0"
127
145
  required_rubygems_version: !ruby/object:Gem::Requirement
128
146
  none: false
129
147
  requirements:
130
148
  - - ">="
131
149
  - !ruby/object:Gem::Version
150
+ hash: -927429969750751341
151
+ segments:
152
+ - 0
132
153
  version: "0"
133
154
  requirements: []
134
155