active_remote-cached 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/active_remote-cached/cache.rb +1 -8
- data/lib/active_remote-cached/version.rb +1 -1
- data/lib/active_remote-cached.rb +12 -0
- data/spec/cache_spec.rb +18 -12
- data/spec/cached_find_methods_spec.rb +6 -0
- data/spec/cached_search_methods_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9872e1d79f0ce74478d865b9610ac1f7fbfdca51
|
4
|
+
data.tar.gz: 2d0f206d646b9184b916c49a49ff74aabb1eb42a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6b752495900bf6fe139b68321f7b9d725bc54843df72721ef44c719f8d197a774e38a5a2e3d36ff2b0ed3b4ace2d570704228629ceb9d2e1d89420d9593096a
|
7
|
+
data.tar.gz: 3ff9109ed522147871f4a93265b6993e333ba42772d703ad81456aff079423d74dbe1f398c3ae6c5222a0456bb9abc0271cf99268d43bdbcbcb95fa1e3844a4c
|
@@ -7,6 +7,7 @@ module ActiveRemote::Cached
|
|
7
7
|
def initialize(new_cache_provider)
|
8
8
|
@cache_provider = new_cache_provider
|
9
9
|
validate_provider_method_present(:delete)
|
10
|
+
validate_provider_method_present(:exist?)
|
10
11
|
validate_provider_method_present(:fetch)
|
11
12
|
validate_provider_method_present(:read)
|
12
13
|
validate_provider_method_present(:write)
|
@@ -14,14 +15,6 @@ module ActiveRemote::Cached
|
|
14
15
|
super(@cache_provider)
|
15
16
|
end
|
16
17
|
|
17
|
-
def exist?(key)
|
18
|
-
if self.cache_provider.respond_to?(:exist?)
|
19
|
-
self.cache_provider.exist?(key)
|
20
|
-
else
|
21
|
-
!self.cache_provider.read(key).nil?
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
18
|
private
|
26
19
|
|
27
20
|
def validate_provider_method_present(method_name)
|
data/lib/active_remote-cached.rb
CHANGED
@@ -37,6 +37,18 @@ module ActiveRemote
|
|
37
37
|
cached_finders_for(*keys)
|
38
38
|
end
|
39
39
|
|
40
|
+
def cached_find(argument_hash, options = {})
|
41
|
+
method_name = _cached_find_method_name(argument_hash.keys)
|
42
|
+
arguments = argument_hash.values
|
43
|
+
__send__(method_name, *arguments, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def cached_search(argument_hash, options = {})
|
47
|
+
method_name = _cached_search_method_name(argument_hash.keys)
|
48
|
+
arguments = argument_hash.values
|
49
|
+
__send__(method_name, *arguments, options)
|
50
|
+
end
|
51
|
+
|
40
52
|
##
|
41
53
|
# Underscored Methods
|
42
54
|
#
|
data/spec/cache_spec.rb
CHANGED
@@ -2,28 +2,34 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ::ActiveRemote::Cached::Cache do
|
4
4
|
describe "API" do
|
5
|
-
it "validates #write present" do
|
6
|
-
cache = OpenStruct.new(:read => nil, :delete => nil, :fetch => nil, :exist? => nil)
|
7
|
-
error = lambda { ::ActiveRemote::Cached.cache(cache)}.must_raise(RuntimeError)
|
8
|
-
error.message.must_match(/respond_to.*write/i)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "validates #read present" do
|
12
|
-
cache = OpenStruct.new(:write => nil, :delete => nil, :fetch => nil, :exist? => nil)
|
13
|
-
error = lambda { ::ActiveRemote::Cached.cache(cache) }.must_raise(RuntimeError)
|
14
|
-
error.message.must_match(/respond_to.*read/i)
|
15
|
-
end
|
16
|
-
|
17
5
|
it "validates #delete present" do
|
18
6
|
cache = OpenStruct.new(:write => nil, :fetch => nil, :read => nil, :exist? => nil)
|
19
7
|
error = lambda { ::ActiveRemote::Cached.cache(cache) }.must_raise(RuntimeError)
|
20
8
|
error.message.must_match(/respond_to.*delete/i)
|
21
9
|
end
|
22
10
|
|
11
|
+
it "validates #exist? present" do
|
12
|
+
cache = OpenStruct.new(:write => nil, :delete => nil, :read => nil, :fetch => nil)
|
13
|
+
error = lambda { ::ActiveRemote::Cached.cache(cache) }.must_raise(RuntimeError)
|
14
|
+
error.message.must_match(/respond_to.*exist/i)
|
15
|
+
end
|
16
|
+
|
23
17
|
it "validates #fetch present" do
|
24
18
|
cache = OpenStruct.new(:write => nil, :delete => nil, :read => nil, :exist? => nil)
|
25
19
|
error = lambda { ::ActiveRemote::Cached.cache(cache) }.must_raise(RuntimeError)
|
26
20
|
error.message.must_match(/respond_to.*fetch/i)
|
27
21
|
end
|
22
|
+
|
23
|
+
it "validates #read present" do
|
24
|
+
cache = OpenStruct.new(:write => nil, :delete => nil, :fetch => nil, :exist? => nil)
|
25
|
+
error = lambda { ::ActiveRemote::Cached.cache(cache) }.must_raise(RuntimeError)
|
26
|
+
error.message.must_match(/respond_to.*read/i)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "validates #write present" do
|
30
|
+
cache = OpenStruct.new(:read => nil, :delete => nil, :fetch => nil, :exist? => nil)
|
31
|
+
error = lambda { ::ActiveRemote::Cached.cache(cache)}.must_raise(RuntimeError)
|
32
|
+
error.message.must_match(/respond_to.*write/i)
|
33
|
+
end
|
28
34
|
end
|
29
35
|
end
|
@@ -53,6 +53,12 @@ describe FindMethodClass do
|
|
53
53
|
::ActiveRemote::Cached.default_options({})
|
54
54
|
end
|
55
55
|
|
56
|
+
it "executes find_by_guid when cached_find with guid called" do
|
57
|
+
FindMethodClass.stub(:find, :hello) do
|
58
|
+
FindMethodClass.cached_find(:guid => :guid).must_equal(:hello)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
56
62
|
it "executes the fetch block if not present in cache" do
|
57
63
|
FindMethodClass.stub(:find, :hello) do
|
58
64
|
FindMethodClass.cached_find_by_guid(:guid).must_equal(:hello)
|
@@ -53,6 +53,12 @@ describe SearchMethodClass do
|
|
53
53
|
::ActiveRemote::Cached.default_options({})
|
54
54
|
end
|
55
55
|
|
56
|
+
it "executes search_by_guid when cached_search with guid called" do
|
57
|
+
FindMethodClass.stub(:search, :hello) do
|
58
|
+
FindMethodClass.cached_search(:guid => :guid).must_equal(:hello)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
56
62
|
it "executes the fetch block if not present in cache" do
|
57
63
|
SearchMethodClass.stub(:search, :hello) do
|
58
64
|
SearchMethodClass.cached_search_by_guid(:guid).must_equal(:hello)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_remote-cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dewitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_remote
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.1.11
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Provides a configuration for caching mechanisms and finders on ActiveRemote
|