looksy 0.0.4 → 0.0.5

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.
@@ -5,6 +5,14 @@ module Looksy
5
5
  end
6
6
 
7
7
  module ClassMethods
8
+ def cache_store
9
+ @cache_store ||= defined?(Rails) ? Rails.cache : Looksy::NullCache.new
10
+ end
11
+
12
+ def cache_store=(store)
13
+ @cache_store = store
14
+ end
15
+
8
16
  def cache_key
9
17
  @cache_key ||= [self.name.downcase, 'all'].join('/')
10
18
  end
@@ -41,7 +49,7 @@ module Looksy
41
49
  private
42
50
 
43
51
  def lookup
44
- @lookup ||= Looksy::Lookup.new(self, defined?(Rails) ? Rails.cache : Looksy::NullCache.new)
52
+ @lookup ||= Looksy::Lookup.new(self, cache_store)
45
53
  end
46
54
  end
47
55
  end
@@ -1,3 +1,3 @@
1
1
  module Looksy
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -4,7 +4,34 @@ require "support/record"
4
4
  describe Looksy::Cacheable do
5
5
  let(:klass) { Record }
6
6
 
7
+ describe '.cache_store' do
8
+ after { klass.cache_store = nil }
9
+
10
+ context 'when not set' do
11
+ context 'when using Rails' do
12
+ it 'returns the cache store from Rails'
13
+ end
14
+
15
+ context 'when not using Rails' do
16
+ it 'returns the default cache store' do
17
+ klass.cache_store.should be_a(Looksy::NullCache)
18
+ end
19
+ end
20
+ end
21
+
22
+ context 'when set' do
23
+ let(:store) { TestCacheStore.new }
24
+
25
+ it 'returns the correct cache store' do
26
+ klass.cache_store = store
27
+ klass.cache_store.should eql(store)
28
+ end
29
+ end
30
+ end
31
+
7
32
  describe '.cache_key' do
33
+ after { klass.cache_key = nil }
34
+
8
35
  context 'when not set' do
9
36
  it 'returns the default cache key' do
10
37
  klass.cache_key.should eql('record/all')
@@ -20,6 +47,8 @@ describe Looksy::Cacheable do
20
47
  end
21
48
 
22
49
  describe '.cache_options' do
50
+ after { klass.cache_options = nil }
51
+
23
52
  context 'when not set' do
24
53
  it 'returns the default cache options' do
25
54
  klass.cache_options.should eql({})
@@ -27,24 +27,8 @@ class Record < Struct.new(:id, :name, :type)
27
27
  end
28
28
  end
29
29
 
30
- class OtherRecord < Struct.new(:id)
31
- include Looksy::Cacheable
32
-
33
- def self.all
34
- @all ||= [new(1), new(2), new(3)]
30
+ class TestCacheStore
31
+ def fetch(key, options)
32
+ nil
35
33
  end
36
-
37
- def self.first
38
- all.first
39
- end
40
-
41
- def self.last
42
- all.last
43
- end
44
-
45
- def attributes
46
- {
47
- "id" => id
48
- }
49
- end
50
- end
34
+ end
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
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-16 00:00:00.000000000 -07:00
12
+ date: 2013-07-17 00:00:00.000000000 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &9388700 !ruby/object:Gem::Requirement
17
+ requirement: &257341200 !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: *9388700
25
+ version_requirements: *257341200
26
26
  description: Add a caching layer to your ActiveRecord models that represent look up
27
27
  tables
28
28
  email: