laserlemon-cache_flow 0.1.1 → 0.1.2

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.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/cache_flow.gemspec +1 -1
  3. data/lib/cache_flow.rb +29 -13
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/cache_flow.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cache_flow}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["laserlemon"]
data/lib/cache_flow.rb CHANGED
@@ -30,27 +30,43 @@ module LaserLemon
30
30
  end
31
31
 
32
32
  module InstanceMethods
33
- def to_xml_with_cache_flow(options = {})
34
- with_cache_flow(:xml, options) do
35
- to_xml_without_cache_flow(options)
33
+ def to_xml_with_cache_flow(options = {}, &block)
34
+ if cache_xml?(options, &block)
35
+ key = xml_cache_key(options.merge!(:cache => false))
36
+ value = to_xml_without_cache_flow(options, &block)
37
+ Rails.cache.fetch(key){ value.respond_to?(:dup) ? value.dup : value }
38
+ else
39
+ to_xml_without_cache_flow(options, &block)
36
40
  end
37
41
  end
38
42
 
39
- def to_json_with_cache_flow(options = {})
40
- with_cache_flow(:json, options) do
41
- to_json_without_cache_flow(options)
43
+ def to_json_with_cache_flow(options = {}, &block)
44
+ if cache_json?(options)
45
+ key = json_cache_key(options.merge!(:cache => false))
46
+ value = to_json_without_cache_flow(options, &block)
47
+ Rails.cache.fetch(key){ value.respond_to?(:dup) ? value.dup : value }
48
+ else
49
+ to_json_without_cache_flow(options, &block)
42
50
  end
43
51
  end
44
52
 
45
53
  private
46
54
 
47
- def with_cache_flow(extension, options, &block)
48
- if options.has_key?(:cache) ? options.delete(:cache) : self.class.cache_serialization
49
- options.merge!(:cache => false)
50
- key, value = send("#{extension}_cache_key", options), yield
51
- Rails.cache.fetch(key){ value.respond_to?(:dup) ? value.dup : value }
52
- else
53
- yield
55
+ def cache_xml?(options, &block)
56
+ case
57
+ when block_given?, options.has_key?(:procs) then false
58
+ else cache_serialization?(options)
59
+ end
60
+ end
61
+
62
+ def cache_json?(options)
63
+ cache_serialization?(options)
64
+ end
65
+
66
+ def cache_serialization?(options)
67
+ case
68
+ when options.has_key?(:cache) then options.delete(:cache)
69
+ else self.class.cache_serialization
54
70
  end
55
71
  end
56
72
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: laserlemon-cache_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - laserlemon