looksy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/looksy/cacheable.rb +31 -38
- data/lib/looksy/version.rb +1 -1
- data/spec/support/record.rb +1 -1
- metadata +3 -3
data/lib/looksy/cacheable.rb
CHANGED
@@ -1,56 +1,49 @@
|
|
1
1
|
module Looksy
|
2
2
|
module Cacheable
|
3
|
+
def cache_key
|
4
|
+
@@cache_key ||= [self.name.downcase, 'all'].join('/')
|
5
|
+
end
|
3
6
|
|
4
|
-
def
|
5
|
-
|
7
|
+
def cache_key=(key)
|
8
|
+
@@cache_key = key
|
6
9
|
end
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
11
|
+
def cache_options
|
12
|
+
@@cache_options ||= {}
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
def cache_options=(options = {})
|
16
|
+
@@cache_options = options
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
def fetch_all
|
20
|
+
lookup.all
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
def fetch_by_id(id)
|
24
|
+
lookup.find_by_id(id)
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
def method_missing(method, *args, &block)
|
28
|
+
if method.match(/^fetch/)
|
29
|
+
method = method.to_s.gsub(/^fetch/, 'find')
|
30
|
+
lookup.send(method, *args, &block)
|
31
|
+
else
|
32
|
+
super
|
27
33
|
end
|
34
|
+
end
|
28
35
|
|
29
|
-
|
30
|
-
lookup.find_by_id(id)
|
31
|
-
end
|
36
|
+
private
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
def lookup
|
39
|
+
@lookup ||= begin
|
40
|
+
cache = if defined?(Rails)
|
41
|
+
Rails.cache
|
37
42
|
else
|
38
|
-
|
43
|
+
Looksy::NullCache.new
|
39
44
|
end
|
40
|
-
end
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
def lookup
|
45
|
-
@lookup ||= begin
|
46
|
-
cache = if defined?(Rails)
|
47
|
-
Rails.cache
|
48
|
-
else
|
49
|
-
Looksy::NullCache.new
|
50
|
-
end
|
51
|
-
|
52
|
-
Looksy::Lookup.new(self, cache)
|
53
|
-
end
|
46
|
+
Looksy::Lookup.new(self, cache)
|
54
47
|
end
|
55
48
|
end
|
56
49
|
end
|
data/lib/looksy/version.rb
CHANGED
data/spec/support/record.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: looksy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &77085200 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *77085200
|
26
26
|
description: Add a caching layer to your ActiveRecord models that represent look up
|
27
27
|
tables
|
28
28
|
email:
|