looksy 0.0.1 → 0.0.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.
@@ -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 self.included(base)
5
- base.extend(ClassMethods)
7
+ def cache_key=(key)
8
+ @@cache_key = key
6
9
  end
7
10
 
8
- module ClassMethods
9
- def cache_key
10
- @@cache_key ||= [self.name.downcase, 'all'].join('/')
11
- end
11
+ def cache_options
12
+ @@cache_options ||= {}
13
+ end
12
14
 
13
- def cache_key=(key)
14
- @@cache_key = key
15
- end
15
+ def cache_options=(options = {})
16
+ @@cache_options = options
17
+ end
16
18
 
17
- def cache_options
18
- @@cache_options ||= {}
19
- end
19
+ def fetch_all
20
+ lookup.all
21
+ end
20
22
 
21
- def cache_options=(options = {})
22
- @@cache_options = options
23
- end
23
+ def fetch_by_id(id)
24
+ lookup.find_by_id(id)
25
+ end
24
26
 
25
- def fetch_all
26
- lookup.all
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
- def fetch_by_id(id)
30
- lookup.find_by_id(id)
31
- end
36
+ private
32
37
 
33
- def method_missing(method, *args, &block)
34
- if method.match(/^fetch/)
35
- method = method.to_s.gsub(/^fetch/, 'find')
36
- lookup.send(method, *args, &block)
38
+ def lookup
39
+ @lookup ||= begin
40
+ cache = if defined?(Rails)
41
+ Rails.cache
37
42
  else
38
- super
43
+ Looksy::NullCache.new
39
44
  end
40
- end
41
45
 
42
- private
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
@@ -1,3 +1,3 @@
1
1
  module Looksy
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class Record < Struct.new(:id, :name, :type)
2
- include Looksy::Cacheable
2
+ extend Looksy::Cacheable
3
3
 
4
4
  def self.all
5
5
  @all ||= [
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.1
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: &184782620 !ruby/object:Gem::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: *184782620
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: