looksy 0.0.8 → 0.1.0
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.
- data/lib/looksy.rb +1 -1
- data/lib/looksy/cache.rb +7 -0
- data/lib/looksy/cache/memory.rb +25 -0
- data/lib/looksy/cache/null.rb +9 -0
- data/lib/looksy/cacheable.rb +1 -1
- data/lib/looksy/version.rb +1 -1
- data/spec/lib/cache/memory_spec.rb +72 -0
- data/spec/lib/cache/null_spec.rb +19 -0
- data/spec/lib/cacheable_spec.rb +1 -1
- data/spec/lib/repository_spec.rb +1 -1
- metadata +11 -5
- data/lib/looksy/null_cache.rb +0 -7
data/lib/looksy.rb
CHANGED
data/lib/looksy/cache.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Looksy
|
2
|
+
module Cache
|
3
|
+
class Memory
|
4
|
+
def initialize
|
5
|
+
@data = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def fetch(key, options = {}, &block)
|
9
|
+
unless @data[key]
|
10
|
+
@data[key] = block.call if block_given?
|
11
|
+
end
|
12
|
+
|
13
|
+
@data[key]
|
14
|
+
end
|
15
|
+
|
16
|
+
def has_key?(key)
|
17
|
+
true unless @data[key].nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def clear
|
21
|
+
@data = {}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/looksy/cacheable.rb
CHANGED
data/lib/looksy/version.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Looksy::Cache::Memory do
|
4
|
+
let(:cache) { Looksy::Cache::Memory.new }
|
5
|
+
|
6
|
+
after { cache.clear }
|
7
|
+
|
8
|
+
describe '#fetch' do
|
9
|
+
context 'when passing block' do
|
10
|
+
context 'when key exists' do
|
11
|
+
before { cache.fetch('block_with_key') { 'result' } }
|
12
|
+
|
13
|
+
it 'returns the correct data' do
|
14
|
+
cache.fetch('block_with_key').should eql('result')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when key does not exist' do
|
19
|
+
it 'stores the data' do
|
20
|
+
cache.fetch('block_without_key') { 'result' }
|
21
|
+
cache.should have_key('block_without_key')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns the correct data' do
|
25
|
+
cache.fetch('block_without_key') { 'result' }
|
26
|
+
cache.fetch('block_without_key').should eql('result')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when not passing block' do
|
32
|
+
context 'when key exists' do
|
33
|
+
before { cache.fetch('key_without_block') { 'result' } }
|
34
|
+
|
35
|
+
it 'returns the correct data' do
|
36
|
+
cache.fetch('key_without_block').should eql('result')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when key does not exist' do
|
41
|
+
it 'returns nil' do
|
42
|
+
cache.fetch('no_key_without_block').should be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#clear' do
|
49
|
+
before { cache.fetch('clear_data') { 'result'} }
|
50
|
+
|
51
|
+
it 'clears the stored data' do
|
52
|
+
cache.clear
|
53
|
+
cache.should_not have_key('clear_data')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#has_key?' do
|
58
|
+
context 'when has key' do
|
59
|
+
before { cache.fetch('has_key') { 'result' } }
|
60
|
+
|
61
|
+
it 'returns true' do
|
62
|
+
cache.should have_key('has_key')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when does not have key' do
|
67
|
+
it 'returns false' do
|
68
|
+
cache.should_not have_key('dont_have_key')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Looksy::Cache::Null do
|
4
|
+
let(:cache) { Looksy::Cache::Null.new }
|
5
|
+
|
6
|
+
describe '#fetch' do
|
7
|
+
context 'when passing block' do
|
8
|
+
it 'returns the result of the block' do
|
9
|
+
cache.fetch('key') { 'result' }.should eql('result')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when not passing block' do
|
14
|
+
it 'returns nil' do
|
15
|
+
cache.fetch('key').should be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/lib/cacheable_spec.rb
CHANGED
data/spec/lib/repository_spec.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.1.0
|
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-
|
12
|
+
date: 2013-07-30 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: &
|
17
|
+
requirement: &65060540 !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: *65060540
|
26
26
|
description: Add a caching layer to your ActiveRecord models that represent look up
|
27
27
|
tables
|
28
28
|
email:
|
@@ -38,12 +38,16 @@ files:
|
|
38
38
|
- README.md
|
39
39
|
- Rakefile
|
40
40
|
- lib/looksy.rb
|
41
|
+
- lib/looksy/cache.rb
|
42
|
+
- lib/looksy/cache/memory.rb
|
43
|
+
- lib/looksy/cache/null.rb
|
41
44
|
- lib/looksy/cacheable.rb
|
42
45
|
- lib/looksy/dynamic_find_match.rb
|
43
|
-
- lib/looksy/null_cache.rb
|
44
46
|
- lib/looksy/repository.rb
|
45
47
|
- lib/looksy/version.rb
|
46
48
|
- looksy.gemspec
|
49
|
+
- spec/lib/cache/memory_spec.rb
|
50
|
+
- spec/lib/cache/null_spec.rb
|
47
51
|
- spec/lib/cacheable_spec.rb
|
48
52
|
- spec/lib/dynamic_find_match_spec.rb
|
49
53
|
- spec/lib/repository_spec.rb
|
@@ -75,6 +79,8 @@ signing_key:
|
|
75
79
|
specification_version: 3
|
76
80
|
summary: Caching layer for look up tables
|
77
81
|
test_files:
|
82
|
+
- spec/lib/cache/memory_spec.rb
|
83
|
+
- spec/lib/cache/null_spec.rb
|
78
84
|
- spec/lib/cacheable_spec.rb
|
79
85
|
- spec/lib/dynamic_find_match_spec.rb
|
80
86
|
- spec/lib/repository_spec.rb
|