review_and_approve 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,6 +42,9 @@ review_and_approve :by => [:as_json, :to_json]
42
42
 
43
43
  review_and_approve :field => :published
44
44
  # Override the field used to track whether we are publishing or not.
45
+
46
+ review_and_approve :cache_key => Proc.new{|object, method_name| #Generate key string}
47
+ # Override the way the gem creates a key for reading/writing to the cache
45
48
  ```
46
49
 
47
50
  ### Showing differences from published version
@@ -4,8 +4,9 @@ module ReviewAndApprove
4
4
  # Extracting options:
5
5
  # 1. methods to cache - option :by, default value [:as_json]
6
6
  # 2. attribute to track as published - option :field, default value :publish
7
- methods = [:as_json]
8
7
  field = :publish
8
+ methods = [:as_json]
9
+ key_proc = Proc.new{|obj, method| "ReviewAndApprove_#{obj.class.name}_#{obj.id}_#{method}"}
9
10
  args.each do |arg|
10
11
  if arg.is_a? Hash
11
12
  if !arg[:by].nil?
@@ -14,6 +15,9 @@ module ReviewAndApprove
14
15
  if !arg[:field].nil?
15
16
  field = arg[:field]
16
17
  end
18
+ if !arg[:cache_key].nil?
19
+ key_proc = arg[:cache_key]
20
+ end
17
21
  end
18
22
  end
19
23
 
@@ -26,7 +30,7 @@ module ReviewAndApprove
26
30
  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"
27
31
  methods.each do |method|
28
32
  # Refresh all caches
29
- Rails.cache.write("ReviewAndApprove_#{self.class.name}_#{self.id}_#{method}", self.send(method))
33
+ Rails.cache.write(key_proc.call(self, method), self.send(method))
30
34
  end
31
35
  end
32
36
 
@@ -34,7 +38,7 @@ module ReviewAndApprove
34
38
  end
35
39
 
36
40
  send(:define_method, :published_version) do |method_name|
37
- Rails.cache.read("ReviewAndApprove_#{self.class.name}_#{self.id}_#{method_name}")
41
+ Rails.cache.read(key_proc.call(self, method_name))
38
42
  end
39
43
 
40
44
  send(:define_method, :mass_assignment_authorizer) do |role = :default|
@@ -1,3 +1,3 @@
1
1
  module ReviewAndApprove
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paramveer Singh