Module: Looksy::Cacheable::ClassMethods
- Defined in:
- lib/looksy/cacheable.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/looksy/cacheable.rb', line 48
def method_missing(method, *args, &block)
if method.match(/^fetch/)
method = method.to_s.gsub(/^fetch/, 'find')
repository.send(method, *args, &block)
else
super
end
end
|
Instance Method Details
#cache_key ⇒ Object
16
17
18
|
# File 'lib/looksy/cacheable.rb', line 16
def cache_key
@cache_key ||= [self.name.downcase, 'all'].join('/')
end
|
#cache_key=(key) ⇒ Object
20
21
22
|
# File 'lib/looksy/cacheable.rb', line 20
def cache_key=(key)
@cache_key = key
end
|
#cache_options ⇒ Object
24
25
26
|
# File 'lib/looksy/cacheable.rb', line 24
def cache_options
@cache_options ||= {}
end
|
#cache_options=(options = {}) ⇒ Object
28
29
30
|
# File 'lib/looksy/cacheable.rb', line 28
def cache_options=(options = {})
@cache_options = options
end
|
#cache_store ⇒ Object
8
9
10
|
# File 'lib/looksy/cacheable.rb', line 8
def cache_store
@cache_store ||= defined?(Rails) ? Rails.cache : Looksy::NullCache.new
end
|
#cache_store=(store) ⇒ Object
12
13
14
|
# File 'lib/looksy/cacheable.rb', line 12
def cache_store=(store)
@cache_store = store
end
|
#fetch_all ⇒ Object
32
33
34
|
# File 'lib/looksy/cacheable.rb', line 32
def fetch_all
repository.all
end
|
#fetch_by_id(id) ⇒ Object
44
45
46
|
# File 'lib/looksy/cacheable.rb', line 44
def fetch_by_id(id)
repository.find_by_id(id)
end
|
#fetch_first ⇒ Object
36
37
38
|
# File 'lib/looksy/cacheable.rb', line 36
def fetch_first
repository.first
end
|
#fetch_last ⇒ Object
40
41
42
|
# File 'lib/looksy/cacheable.rb', line 40
def fetch_last
repository.last
end
|