review_and_approve 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -2
- data/app/views/review_and_approve/_delta.html.erb +3 -9
- data/app/views/review_and_approve/_line_item.html.erb +11 -22
- data/lib/review_and_approve/hash_diff.rb +18 -0
- data/lib/review_and_approve/model_additions.rb +15 -3
- data/lib/review_and_approve/version.rb +1 -1
- data/lib/review_and_approve.rb +1 -0
- metadata +3 -2
data/README.md
CHANGED
@@ -60,16 +60,19 @@ review_and_approve :cache_key => Proc.new{|object, method_name| #Generate key st
|
|
60
60
|
```
|
61
61
|
|
62
62
|
### Showing differences from published version
|
63
|
-
|
63
|
+
Methods called `published_version` and `current_version` are defined on the model that provides access to cached methods as of the last published or current versions. For example:
|
64
64
|
|
65
65
|
```ruby
|
66
66
|
@product.published_version(:as_json)
|
67
67
|
# => returns the as_json hash from the last time the product was published
|
68
68
|
|
69
|
+
@product.current_version(:as_json)
|
70
|
+
# => returns the as_json hash for the current iteration. It is advisable to use this to avoid getting bogged down by changes to date/time and other fields because of just saving and retrieving from your cache(i.e. database)
|
71
|
+
|
69
72
|
# Rendering the differences
|
70
73
|
render :partial => "review_and_approve/delta",
|
71
74
|
:locals => {:published => @product.published_version(:as_json),
|
72
|
-
:current => @product.as_json}
|
75
|
+
:current => @product.current_version(:as_json)}
|
73
76
|
# Given two hashes (before/after), this will render the changes in a table
|
74
77
|
|
75
78
|
#styling the differences
|
@@ -1,5 +1,6 @@
|
|
1
1
|
<% published ||= {} %>
|
2
|
-
<%
|
2
|
+
<% diff = ReviewAndApprove::HashDiff.diff(published,current) %>
|
3
|
+
<% diff_keys = diff.keys %>
|
3
4
|
<div class="review_and_approve">
|
4
5
|
<% if diff_keys.count > 0 %>
|
5
6
|
<table>
|
@@ -13,14 +14,7 @@
|
|
13
14
|
|
14
15
|
<tbody>
|
15
16
|
<% diff_keys.each do |key| %>
|
16
|
-
|
17
|
-
<td><%= key rescue "" %></td>
|
18
|
-
<%# if !published.is_a? Hash and !published.is_a? Array %>
|
19
|
-
<td><%= published || "<BLANK>" %></td>
|
20
|
-
<td><%= current || "<BLANK>" %></td>
|
21
|
-
<%# end %>
|
22
|
-
</tr>
|
23
|
-
<%#= render :partial => 'review_and_approve/line_item', :locals => {:published => published[key], :current => current[key], :key => key, :depth => 0} %>
|
17
|
+
<%= render :partial => 'review_and_approve/line_item', :locals => {:key => key, :diff_val => diff[key], :depth => -1} %>
|
24
18
|
<% end %>
|
25
19
|
</tbody>
|
26
20
|
|
@@ -1,30 +1,19 @@
|
|
1
|
-
|
2
|
-
<% puts "published:#{published rescue ""}" %>
|
3
|
-
<% puts "current:#{current rescue ""}" %>
|
4
|
-
<% puts "key:#{key rescue ""}" %>
|
5
|
-
<% current ||= {} %>
|
1
|
+
|
6
2
|
<tr>
|
7
3
|
<% (0..depth).each do %>
|
8
4
|
<td></td>
|
9
5
|
<% end %>
|
10
6
|
<td><%= key rescue "" %></td>
|
11
|
-
<% if
|
12
|
-
<td><%=
|
13
|
-
<td><%=
|
7
|
+
<% if diff_val.is_a? Array %>
|
8
|
+
<td><%= diff_val[0] || "<BLANK>" %></td>
|
9
|
+
<td><%= diff_val[1] || "<BLANK>" %></td>
|
14
10
|
<% end %>
|
15
11
|
</tr>
|
16
|
-
<% if
|
17
|
-
<%
|
18
|
-
|
19
|
-
<% pub = (published.include? item) ? item : nil %>
|
20
|
-
<% cur = (current.include? item) ? item : nil %>
|
21
|
-
<%= render :partial => 'review_and_approve/line_item',
|
22
|
-
:locals => {:depth => depth+1, :published => pub, :current => cur} %>
|
23
|
-
<% end %>
|
12
|
+
<% if diff_val.is_a? Hash %>
|
13
|
+
<% diff_val.keys.each do |key| %>
|
14
|
+
<%= render :partial => 'review_and_approve/line_item', :locals => {:key => key, :diff_val => diff_key[key], :depth => depth+1} %>
|
24
15
|
<% end %>
|
25
|
-
<%
|
26
|
-
<%
|
27
|
-
<%
|
28
|
-
|
29
|
-
<% end %>
|
30
|
-
<% end %>
|
16
|
+
<% elsif !diff_val.is_a? Array or diff_val.length>2 %>
|
17
|
+
<% debugger %>
|
18
|
+
<% raise Exception.new %>
|
19
|
+
<% end %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ReviewAndApprove
|
2
|
+
module HashDiff
|
3
|
+
def diff(orig, other)
|
4
|
+
(orig.keys + other.keys).uniq.inject({}) do |memo, key|
|
5
|
+
unless orig[key] == other[key]
|
6
|
+
if orig[key].kind_of?(Hash) && other[key].kind_of?(Hash)
|
7
|
+
memo[key] = ReviewAndApprove::HashDiff.diff(orig[key], other[key])
|
8
|
+
else
|
9
|
+
memo[key] = [orig[key], other[key]]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
memo
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module_function :diff
|
17
|
+
end
|
18
|
+
end
|
@@ -36,20 +36,32 @@ module ReviewAndApprove
|
|
36
36
|
#If we are publishing the record
|
37
37
|
if published and (published==true or published=="true" or published=="on" or self.send(field).to_i>0 rescue false) #in case the field gets set to "0" and "1"
|
38
38
|
methods.each do |method|
|
39
|
-
# Refresh
|
40
|
-
cr = CacheRecord.find_or_initialize_by_key(key_proc.call(self, method))
|
39
|
+
# Refresh published cache
|
40
|
+
cr = CacheRecord.find_or_initialize_by_key("#{key_proc.call(self, method)}_published_version")
|
41
41
|
cr.cache_data = self.send(method)
|
42
42
|
cr.save
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
methods.each do |method|
|
47
|
+
#Refresh current value cache
|
48
|
+
cr = CacheRecord.find_or_initialize_by_key("#{key_proc.call(self, method)}_current_version")
|
49
|
+
cr.cache_data = self.send(method)
|
50
|
+
cr.save
|
51
|
+
end
|
52
|
+
|
46
53
|
true
|
47
54
|
end
|
48
55
|
|
49
56
|
send(:define_method, :published_version) do |method_name|
|
50
|
-
CacheRecord.find_by_key(key_proc.call(self, method_name)).cache_data rescue nil
|
57
|
+
CacheRecord.find_by_key("#{key_proc.call(self, method_name)}_published_version").cache_data rescue nil
|
51
58
|
end
|
52
59
|
|
60
|
+
send(:define_method, :current_version) do |method_name|
|
61
|
+
CacheRecord.find_by_key("#{key_proc.call(self, method_name)}_current_version").cache_data rescue nil
|
62
|
+
end
|
63
|
+
|
64
|
+
|
53
65
|
send(:define_method, :mass_assignment_authorizer) do |role = :default|
|
54
66
|
# force add the :publish attribute into attr_accessible
|
55
67
|
super(role) + [field]
|
data/lib/review_and_approve.rb
CHANGED
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.
|
5
|
+
version: 0.0.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Paramveer Singh
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-05-
|
13
|
+
date: 2013-05-29 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/review_and_approve/cache_record.rb
|
120
120
|
- lib/review_and_approve/controller_additions.rb
|
121
121
|
- lib/review_and_approve/engine.rb
|
122
|
+
- lib/review_and_approve/hash_diff.rb
|
122
123
|
- lib/review_and_approve/model_additions.rb
|
123
124
|
- lib/review_and_approve/railtie.rb
|
124
125
|
- lib/review_and_approve/version.rb
|