basiccache 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a49be3db84d2126fa39a6836c55ec560f0a3db8
4
- data.tar.gz: 6b3a772fcd807e71442f17b790f951fa96ac78da
3
+ metadata.gz: d4f71e13e981841f75469a57635fb62fa2a05c13
4
+ data.tar.gz: 481c5488cb94027f7eeb5c6b73c553efca63c3a7
5
5
  SHA512:
6
- metadata.gz: 1cd94168231bcf330a6f5c878b05da48181b0df67287640eadfe7ba9b22b9437b405b480f5f64864f1e083c61d98531fa3fa92013079647f900199d63c8fc8b2
7
- data.tar.gz: 13554660770b5dd53d1c4d30be3fb7f83a81cd077f63a77c64282bec33259b12b27478e3e88cf366f68aeef83c5e725a1feae21e0ce6624ed0ef9e82be363752
6
+ metadata.gz: 294d82efd515d209d81c6912feb364acd94cfd7c535186d2354f98d36841a35f8877fa3b2148a38bc8b80bafdd0336d1476a233a6f239652d138de2b3d4c489e
7
+ data.tar.gz: b96dd632fad79b12bb513642d179cc7886f7c98d482652a634a9cb3be45ac18df3ded46b6ecbe142dda75099307f98615a1470c605762d08ab5ce089e00c0831
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
+ - 2.1.2
5
+ - 2.1.1
4
6
  - 2.1.0
5
7
  - 2.0.0
6
8
  - 1.9.3
@@ -8,7 +10,6 @@ notifications:
8
10
  email: false
9
11
  irc:
10
12
  channels:
11
- - ircs://irc.oftc.net:6697#akerl
12
- channel_key: sekrit
13
+ - secure: NHoXuLan4NfkC00oLCXcXoYTlfFfJG/YpyGfhgk89EKBhymmBKdgYvAF1BUZ6a7olhTxt8CTNTKa8xu2lF4ET1JyHkFQwYTjp0HvCY0mpVtm7PbBEzoiK7nQWH1bkBMIYHOcmyBHmtK71iFXlXMFOxz1T1MfjLHq2PSQ6OlB6OU=
13
14
  template:
14
- - '%{repository}/%{branch}/%{build_number}: %{message} -- %{build_url}'
15
+ - "%{repository}/%{branch}/%{build_number}: %{message} -- %{build_url}"
data/Rakefile CHANGED
@@ -2,24 +2,13 @@ require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'rubocop/rake_task'
4
4
 
5
- desc 'Update bundle'
6
- task :bundle do
7
- `bundle update`
8
- end
9
-
10
5
  desc 'Run tests'
11
6
  RSpec::Core::RakeTask.new(:spec)
12
7
 
13
8
  desc 'Run Rubocop on the gem'
14
- Rubocop::RakeTask.new(:rubocop) do |task|
9
+ RuboCop::RakeTask.new(:rubocop) do |task|
15
10
  task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
16
11
  task.fail_on_error = true
17
12
  end
18
13
 
19
- desc 'Run travis-lint on .travis.yml'
20
- task :travislint do
21
- print 'There may be an issue with your .travis.yml' unless system('travis-lint')
22
- end
23
-
24
- task default: [:spec, :travislint, :rubocop, :build, :install]
25
- task release: [:bundle]
14
+ task default: [:spec, :rubocop, :build, :install]
data/basiccache.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'basiccache'
3
- s.version = '0.1.0'
3
+ s.version = '0.2.0'
4
4
  s.date = Time.now.strftime("%Y-%m-%d")
5
5
  s.summary = 'Provides a minimal key/value caching layer'
6
6
  s.description = "Allows an application to dynamically cache values and retrieve them later"
@@ -12,12 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.files = `git ls-files`.split
13
13
  s.test_files = `git ls-files spec/*`.split
14
14
 
15
- s.add_development_dependency 'rubocop'
16
- s.add_development_dependency 'travis-lint'
17
- s.add_development_dependency 'rake'
18
- s.add_development_dependency 'coveralls'
19
- s.add_development_dependency 'rspec'
20
- s.add_development_dependency 'fuubar'
21
- s.add_development_dependency 'parser'
15
+ s.add_development_dependency 'rubocop', '~> 0.24.0'
16
+ s.add_development_dependency 'rake', '~> 10.3.2'
17
+ s.add_development_dependency 'coveralls', '~> 0.7.0'
18
+ s.add_development_dependency 'rspec', '~> 3.0.0'
19
+ s.add_development_dependency 'fuubar', '~> 2.0.0.rc1'
20
+ s.add_development_dependency 'timecop', '~> 0.7.1'
22
21
  end
23
-
data/lib/basiccache.rb CHANGED
@@ -25,7 +25,8 @@ module BasicCache
25
25
  end
26
26
  end
27
27
 
28
- require 'stores/store'
29
- require 'caches/cache'
30
- require 'caches/timecache'
31
- require 'methodcacher'
28
+ require 'basiccache/stores/store'
29
+ require 'basiccache/stores/nullstore'
30
+ require 'basiccache/caches/cache'
31
+ require 'basiccache/caches/timecache'
32
+ require 'basiccache/methodcacher'
File without changes
File without changes
@@ -13,7 +13,7 @@ module MethodCacher
13
13
  (class << self; self; end).class_eval do
14
14
  alias_method uncached_name, name
15
15
  define_method(name) do |*a, &b|
16
- cache.cache(name) { send uncached_name, *a }
16
+ cache.cache(name) { send uncached_name, *a, &b }
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,56 @@
1
+ module BasicCache
2
+ ##
3
+ # No-op store object, does not store information
4
+ class NullStore
5
+ attr_reader :raw
6
+
7
+ ##
8
+ # Generate an empty store
9
+
10
+ def initialize
11
+ @raw = nil
12
+ end
13
+
14
+ ##
15
+ # Clears a specified key or the whole store
16
+
17
+ def clear!(*_)
18
+ true
19
+ end
20
+
21
+ ##
22
+ # Retrieve a key
23
+
24
+ def [](_)
25
+ nil
26
+ end
27
+
28
+ ##
29
+ # Set a key
30
+
31
+ def []=(_, value)
32
+ value
33
+ end
34
+
35
+ ##
36
+ # Return the size of the store
37
+
38
+ def size
39
+ 0
40
+ end
41
+
42
+ ##
43
+ # Check for a key in the store
44
+
45
+ def include?(_)
46
+ false
47
+ end
48
+
49
+ ##
50
+ # Array of keys in the store
51
+
52
+ def keys
53
+ []
54
+ end
55
+ end
56
+ end
File without changes
@@ -26,20 +26,20 @@ describe BasicCache::Cache do
26
26
  it 'caches values without a key' do
27
27
  subject.cache { 9 }
28
28
  expect(subject.cache { 10 }).to eql 9
29
- expect(subject.include?).to be_true
29
+ expect(subject.include?).to be_truthy
30
30
  end
31
31
  it 'caches values with a key' do
32
32
  subject.cache('c') { 1 }
33
33
  expect(subject.cache('c') { 2 }).to eql 1
34
- expect(subject.include? :c). to be_true
34
+ expect(subject.include? :c). to be_truthy
35
35
  end
36
36
  end
37
37
  describe '#include?' do
38
38
  it 'checks for a value in the cache' do
39
- expect(cache.include? 'a').to be_true
40
- expect(cache.include? :b).to be_true
41
- expect(cache.include? 'z').to be_false
42
- expect(cache.include? names[2]).to be_true
39
+ expect(cache.include? 'a').to be_truthy
40
+ expect(cache.include? :b).to be_truthy
41
+ expect(cache.include? 'z').to be_falsey
42
+ expect(cache.include? names[2]).to be_truthy
43
43
  end
44
44
  end
45
45
  describe '#[]' do
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
+ require 'timecop'
2
3
 
3
4
  describe BasicCache::TimeCache do
4
5
  let(:cache) do
5
- cache = BasicCache::TimeCache.new(lifetime: 1)
6
+ cache = BasicCache::TimeCache.new(lifetime: 10)
6
7
  cache.cache('a') { 3 }
7
8
  cache.cache(:b) { 5 }
8
9
  cache.cache { 9 }
@@ -17,7 +18,7 @@ describe BasicCache::TimeCache do
17
18
  expect(subject.store).to be_an_instance_of BasicCache::Store
18
19
  end
19
20
  it 'has a set lifetime' do
20
- expect(cache.lifetime).to eq 1
21
+ expect(cache.lifetime).to eq 10
21
22
  expect(BasicCache::TimeCache.new.lifetime).to eq 60
22
23
  end
23
24
  describe '#size' do
@@ -27,33 +28,35 @@ describe BasicCache::TimeCache do
27
28
  end
28
29
  it 'does not include expired items in size' do
29
30
  expect(cache.size).to eql 3
30
- sleep 2
31
- expect(cache.size).to eql 0
31
+ Timecop.freeze(Time.now + 60) do
32
+ expect(cache.size).to eql 0
33
+ end
32
34
  end
33
35
  end
34
36
  describe '#cache' do
35
37
  it 'caches values without a key' do
36
38
  subject.cache { 9 }
37
39
  expect(subject.cache { 10 }).to eql 9
38
- expect(subject.include?).to be_true
40
+ expect(subject.include?).to be_truthy
39
41
  end
40
42
  it 'caches values with a key' do
41
43
  subject.cache('c') { 1 }
42
44
  expect(subject.cache('c') { 2 }).to eql 1
43
- expect(subject.include? :c). to be_true
45
+ expect(subject.include? :c). to be_truthy
44
46
  end
45
47
  it 'expires values after their lifetime' do
46
- expect(cache.include? 'a').to be_true
47
- sleep 2
48
- expect(cache.include? 'a').to be_false
48
+ expect(cache.include? 'a').to be_truthy
49
+ Timecop.freeze(Time.now + 60) do
50
+ expect(cache.include? 'a').to be_falsey
51
+ end
49
52
  end
50
53
  end
51
54
  describe '#include?' do
52
55
  it 'checks for a value in the cache' do
53
- expect(cache.include? 'a').to be_true
54
- expect(cache.include? :b).to be_true
55
- expect(cache.include? 'z').to be_false
56
- expect(cache.include? names[2]).to be_true
56
+ expect(cache.include? 'a').to be_truthy
57
+ expect(cache.include? :b).to be_truthy
58
+ expect(cache.include? 'z').to be_falsey
59
+ expect(cache.include? names[2]).to be_truthy
57
60
  end
58
61
  end
59
62
  describe '#[]' do
@@ -64,8 +67,9 @@ describe BasicCache::TimeCache do
64
67
  end
65
68
  it 'will not return an expired key' do
66
69
  expect(cache['a']).to eql 3
67
- sleep 2
68
- expect { cache['a'] }.to raise_error KeyError
70
+ Timecop.freeze(Time.now + 60) do
71
+ expect { cache['a'] }.to raise_error KeyError
72
+ end
69
73
  end
70
74
  end
71
75
  describe '#clear!' do
@@ -93,10 +97,11 @@ describe BasicCache::TimeCache do
93
97
  describe '#prune' do
94
98
  it 'prunes invalid cache entries' do
95
99
  expect(cache.store.size).to eql 3
96
- sleep 2
97
- expect(cache.store.size).to eql 3
98
- expect(cache.prune).to eql [:a, :b, names[2]]
99
- expect(cache.store.size).to eql 0
100
+ Timecop.freeze(Time.now + 60) do
101
+ expect(cache.store.size).to eql 3
102
+ expect(cache.prune).to eql [:a, :b, names[2]]
103
+ expect(cache.store.size).to eql 0
104
+ end
100
105
  end
101
106
  end
102
107
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'timecop'
2
3
 
3
4
  ##
4
5
  # Example class for testing method caching
@@ -8,7 +9,7 @@ class Example
8
9
  def initialize(skip_cache = false)
9
10
  return if skip_cache
10
11
  enable_caching [:repeat]
11
- enable_caching [:time_repeat], BasicCache::TimeCache.new(lifetime: 1)
12
+ enable_caching [:time_repeat], BasicCache::TimeCache.new(lifetime: 10)
12
13
  end
13
14
 
14
15
  def repeat(input)
@@ -44,8 +45,9 @@ describe MethodCacher do
44
45
  it 'allows a user-supplied cache object' do
45
46
  expect(test_object.time_repeat 2).to eql 2
46
47
  expect(test_object.time_repeat 3).to eql 2
47
- sleep 2
48
- expect(test_object.time_repeat 4).to eql 4
48
+ Timecop.freeze(Time.now + 60) do
49
+ expect(test_object.time_repeat 4).to eql 4
50
+ end
49
51
  end
50
52
  it 'does not override other methods' do
51
53
  expect(test_object.not_cached 7).to eql 7
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe BasicCache::NullStore do
4
+ let(:store) { BasicCache::NullStore.new }
5
+
6
+ describe '#initialize' do
7
+ it 'creates a new null store object' do
8
+ expect(store.raw).to be_nil
9
+ end
10
+ end
11
+ describe '#clear!' do
12
+ it 'always returns true' do
13
+ expect(store.clear!).to be_truthy
14
+ expect(store.clear!(5)).to be_truthy
15
+ end
16
+ end
17
+ describe '#[]' do
18
+ it 'always returns nil' do
19
+ expect(store[1]).to be_nil
20
+ end
21
+ end
22
+ describe '#[]=' do
23
+ it 'returns the provided value' do
24
+ expect(store[6] = 10).to eql 10
25
+ expect(store[6]).to be_nil
26
+ end
27
+ end
28
+ describe '#size' do
29
+ it 'returns zero' do
30
+ expect(store.size).to eql 0
31
+ end
32
+ end
33
+ describe '#include?' do
34
+ it 'always returns false' do
35
+ expect(store.include? :foo).to be_falsey
36
+ expect(store.include? 1).to be_falsey
37
+ end
38
+ end
39
+ describe '#keys' do
40
+ it 'is always an empty array' do
41
+ expect(store.keys).to eql []
42
+ end
43
+ end
44
+ end
@@ -43,8 +43,8 @@ describe BasicCache::Store do
43
43
  end
44
44
  describe '#include?' do
45
45
  it 'checks for a key in the store' do
46
- expect(store.include? :foo).to be_false
47
- expect(store.include? 1).to be_true
46
+ expect(store.include? :foo).to be_falsey
47
+ expect(store.include? 1).to be_truthy
48
48
  end
49
49
  end
50
50
  describe '#keys' do
@@ -9,13 +9,13 @@ describe BasicCache do
9
9
 
10
10
  describe '#caller_name' do
11
11
  it "returns the calling function's name" do
12
- expect(BasicCache.caller_name).to eql 'instance_eval'
12
+ expect(BasicCache.caller_name).to eql 'instance_exec'
13
13
  end
14
14
  it 'uses caller_locations on Ruby 2.0.0+' do
15
- expect(BasicCache::NEW_CALL).to be_true if RUBY_VERSION.to_i >= 2
15
+ expect(BasicCache::NEW_CALL).to be_truthy if RUBY_VERSION.to_i >= 2
16
16
  end
17
17
  it 'uses caller on Ruby 1.x' do
18
- expect(BasicCache::NEW_CALL).to be_false if RUBY_VERSION.to_i < 2
18
+ expect(BasicCache::NEW_CALL).to be_falsey if RUBY_VERSION.to_i < 2
19
19
  end
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,113 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basiccache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-16 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.24.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: travis-lint
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: 0.24.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: 10.3.2
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: 10.3.2
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: coveralls
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ">="
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '0'
47
+ version: 0.7.0
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ">="
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: 0.7.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ">="
59
+ - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: 3.0.0
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
66
+ - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: 3.0.0
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: fuubar
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - ">="
73
+ - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '0'
75
+ version: 2.0.0.rc1
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - ">="
80
+ - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: '0'
82
+ version: 2.0.0.rc1
97
83
  - !ruby/object:Gem::Dependency
98
- name: parser
84
+ name: timecop
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - ">="
87
+ - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: '0'
89
+ version: 0.7.1
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ">="
94
+ - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: '0'
96
+ version: 0.7.1
111
97
  description: Allows an application to dynamically cache values and retrieve them later
112
98
  email: me@lesaker.org
113
99
  executables: []
@@ -124,16 +110,18 @@ files:
124
110
  - Rakefile
125
111
  - basiccache.gemspec
126
112
  - lib/basiccache.rb
127
- - lib/caches/cache.rb
128
- - lib/caches/timecache.rb
129
- - lib/methodcacher.rb
130
- - lib/stores/store.rb
113
+ - lib/basiccache/caches/cache.rb
114
+ - lib/basiccache/caches/timecache.rb
115
+ - lib/basiccache/methodcacher.rb
116
+ - lib/basiccache/stores/nullstore.rb
117
+ - lib/basiccache/stores/store.rb
118
+ - spec/basiccache/caches/cache_spec.rb
119
+ - spec/basiccache/caches/timecache_spec.rb
120
+ - spec/basiccache/methodcacher_spec.rb
121
+ - spec/basiccache/stores/nullstore_spec.rb
122
+ - spec/basiccache/stores/store_spec.rb
131
123
  - spec/basiccache_spec.rb
132
- - spec/caches/cache_spec.rb
133
- - spec/caches/timecache_spec.rb
134
- - spec/methodcacher_spec.rb
135
124
  - spec/spec_helper.rb
136
- - spec/stores/store_spec.rb
137
125
  homepage: https://github.com/akerl/basiccache
138
126
  licenses:
139
127
  - MIT
@@ -154,14 +142,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
142
  version: '0'
155
143
  requirements: []
156
144
  rubyforge_project:
157
- rubygems_version: 2.0.14
145
+ rubygems_version: 2.2.2
158
146
  signing_key:
159
147
  specification_version: 4
160
148
  summary: Provides a minimal key/value caching layer
161
149
  test_files:
150
+ - spec/basiccache/caches/cache_spec.rb
151
+ - spec/basiccache/caches/timecache_spec.rb
152
+ - spec/basiccache/methodcacher_spec.rb
153
+ - spec/basiccache/stores/nullstore_spec.rb
154
+ - spec/basiccache/stores/store_spec.rb
162
155
  - spec/basiccache_spec.rb
163
- - spec/caches/cache_spec.rb
164
- - spec/caches/timecache_spec.rb
165
- - spec/methodcacher_spec.rb
166
156
  - spec/spec_helper.rb
167
- - spec/stores/store_spec.rb