with_timed_cache 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db6c5fa7ef0d80a8b7f22c41b4866bfc72ddfb11
4
- data.tar.gz: 7a48bf47391b62f553ea51111247128380e5801c
3
+ metadata.gz: 91df75cc80b90ede26be4ea3cfdefeb8c98c9f65
4
+ data.tar.gz: 4096decd9e7e83c2fae61556bc218a6f8485fee2
5
5
  SHA512:
6
- metadata.gz: 0234405ce5740080331826bb34fdd213f9be4d93d092204cc82e8c348a9346ae524778ede7d5ec73e993ec4da11ae9eb128e2be819323e949f8f978f43691acb
7
- data.tar.gz: 9534829271c2aeb0c0f8fb67db6eee415a5067a2561d59c054cace9e846f238accc98ac1dc8d197d51854a8214bcaa11e9a16d97f27a7b3c2204c139fb073e5b
6
+ metadata.gz: bb833fe05804bd821e5e6df91fbdf23846bbc0107af1eed96850b8078b6598d630f1d7bfafaa50ca73e150b9303b07698399c12cc92dddcee0f01dfc76f97db9
7
+ data.tar.gz: ae6f3cd73562e6833128a60db01fe3758d5dec203ef8fcbaf2af8f1a6d8750a9e835864fe854594d85881cc2ce3f11de68d3262cace58533dd81162ea85214fc
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.1.2
6
+ script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # WithTimedCache
2
2
 
3
+ [![Build Status](https://travis-ci.org/jordanstephens/with_timed_cache.svg?branch=master)](https://travis-ci.org/jordanstephens/with_timed_cache)
4
+
3
5
  A simple, time-based cache.
4
6
 
5
7
  ## Installation
@@ -16,6 +18,8 @@ Or install it yourself as:
16
18
 
17
19
  $ gem install with_timed_cache
18
20
 
21
+ **Note**: Ruby version 2.0 or later is required.
22
+
19
23
  ## Usage
20
24
 
21
25
  with_timed_cache(key, max_age: 1.hour) do
@@ -27,4 +31,3 @@ Or install it yourself as:
27
31
  * `max_age`: how long to use the cached data, ex: `30.minutes`
28
32
  * `location`: the directory path in which to store cache files
29
33
  * `format`: cache data may be persisted as `:json`, `:yaml`, or the default of marshaling objects to strings will be used.
30
-
@@ -2,7 +2,7 @@ require "with_timed_cache/version"
2
2
  require "with_timed_cache/caches"
3
3
 
4
4
  module WithTimedCache
5
- def with_timed_cache(key, opts)
5
+ def with_timed_cache(key, opts = {})
6
6
  cache = Caches.find_or_create(key, opts)
7
7
 
8
8
  if cache.exists? && !cache.stale?
@@ -27,6 +27,7 @@ module WithTimedCache
27
27
  def cache_class(format = "")
28
28
  format = format.to_s.upcase
29
29
  begin
30
+ # Ruby Version 1.9 and earlier will choke on this line
30
31
  Object.const_get("WithTimedCache::#{format}Cache")
31
32
  rescue
32
33
  raise WithTimedCache::InvalidCacheFormatException
@@ -1,3 +1,3 @@
1
1
  module WithTimedCache
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "rspec"
2
+ require "pry-byebug"
2
3
  require "with_timed_cache"
3
4
 
4
5
  shared_context :with_timed_cache do
@@ -2,16 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe WithTimedCache::Cache do
4
4
  it "knows it's local class name" do
5
- WithTimedCache::Cache.local_class_name.should == "Cache"
5
+ expect(WithTimedCache::Cache.local_class_name).to eql("Cache")
6
6
  end
7
7
 
8
8
  it "has an empty file extension" do
9
- WithTimedCache::Cache.file_extension.should be_empty
9
+ expect(WithTimedCache::Cache.file_extension).to be_empty
10
10
  end
11
11
 
12
12
  it "should have a filename with no extension by default" do
13
13
  cache = WithTimedCache::Cache.new(:foo)
14
- (cache.filename =~ /^.+\..+$/).should be_false
14
+ expect(!!(cache.filename =~ /^.+\..+$/)).to be false
15
15
  end
16
16
  end
17
17
 
@@ -6,22 +6,22 @@ describe WithTimedCache::Caches do
6
6
  key = :find_or_create
7
7
  first_ref = WithTimedCache::Caches.find_or_create(key)
8
8
  second_ref = WithTimedCache::Caches.find_or_create(key)
9
- first_ref.eql?(second_ref).should be_true
9
+ expect(first_ref.eql?(second_ref)).to be true
10
10
  end
11
11
  end
12
12
 
13
13
  describe ".cache_class" do
14
14
  it "will return the constant of the cache class for the given format" do
15
- WithTimedCache::Caches.cache_class(:json).should == WithTimedCache::JSONCache
16
- WithTimedCache::Caches.cache_class("json").should == WithTimedCache::JSONCache
17
- WithTimedCache::Caches.cache_class(:yaml).should == WithTimedCache::YAMLCache
18
- WithTimedCache::Caches.cache_class("").should == WithTimedCache::Cache
19
- WithTimedCache::Caches.cache_class.should == WithTimedCache::Cache
15
+ expect(WithTimedCache::Caches.cache_class(:json)).to eql(WithTimedCache::JSONCache)
16
+ expect(WithTimedCache::Caches.cache_class("json")).to eql(WithTimedCache::JSONCache)
17
+ expect(WithTimedCache::Caches.cache_class(:yaml)).to eql(WithTimedCache::YAMLCache)
18
+ expect(WithTimedCache::Caches.cache_class("")).to eql(WithTimedCache::Cache)
19
+ expect(WithTimedCache::Caches.cache_class).to eql(WithTimedCache::Cache)
20
20
  end
21
21
 
22
22
  it "will return the constant of the cache class for the given format" do
23
23
  expect {
24
- WithTimedCache::Caches.cache_class(:foobar).should == WithTimedCache::JSONCache
24
+ WithTimedCache::Caches.cache_class(:foobar)
25
25
  }.to raise_error WithTimedCache::InvalidCacheFormatException
26
26
  end
27
27
  end
@@ -2,16 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe WithTimedCache::JSONCache do
4
4
  it "knows it's local class name" do
5
- WithTimedCache::JSONCache.local_class_name.should == "JSONCache"
5
+ expect(WithTimedCache::JSONCache.local_class_name).to eql("JSONCache")
6
6
  end
7
7
 
8
8
  it "has a file_extension" do
9
- WithTimedCache::JSONCache.file_extension.should == "json"
9
+ expect(WithTimedCache::JSONCache.file_extension).to eql("json")
10
10
  end
11
11
 
12
12
  it "should have a filename with the '.json' extension" do
13
13
  cache = WithTimedCache::JSONCache.new(:foo)
14
- (cache.filename =~ /^.+\.json$/).should be_true
14
+ expect(!!(cache.filename =~ /^.+\.json$/)).to be true
15
15
  end
16
16
  end
17
17
 
@@ -2,16 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe WithTimedCache::YAMLCache do
4
4
  it "knows it's local class name" do
5
- WithTimedCache::YAMLCache.local_class_name.should == "YAMLCache"
5
+ expect(WithTimedCache::YAMLCache.local_class_name).to eql("YAMLCache")
6
6
  end
7
7
 
8
8
  it "has a file_extension" do
9
- WithTimedCache::YAMLCache.file_extension.should == "yml"
9
+ expect(WithTimedCache::YAMLCache.file_extension).to eql("yml")
10
10
  end
11
11
 
12
12
  it "should have a filename with the '.yml' extension" do
13
13
  cache = WithTimedCache::YAMLCache.new(:foo)
14
- (cache.filename =~ /^.+\.yml$/).should be_true
14
+ expect(!!(cache.filename =~ /^.+\.yml$/)).to be true
15
15
  end
16
16
  end
17
17
 
@@ -5,6 +5,7 @@ describe WithTimedCache do
5
5
 
6
6
  before(:all) do
7
7
  @cache_directory = "spec/data/tmp"
8
+ FileUtils.mkdir_p(@cache_directory)
8
9
  clean_cache_directory
9
10
  end
10
11
 
@@ -12,6 +13,13 @@ describe WithTimedCache do
12
13
  clean_cache_directory
13
14
  end
14
15
 
16
+ it "does not require opts to be passed" do
17
+ val = "NO OPTS"
18
+ FileUtils.mkdir_p("tmp")
19
+ data = with_timed_cache(:no_opts) { val }
20
+ expect(data).to eql(val)
21
+ end
22
+
15
23
  it "caches data for a defined max_age" do
16
24
  original_val = "original value"
17
25
  updated_val = "updated value"
@@ -19,7 +27,7 @@ describe WithTimedCache do
19
27
  data = with_timed_cache(:max_age_1, location: @cache_directory, max_age: 1.minute) do
20
28
  i == 0 ? original_val : updated_val
21
29
  end
22
- data.should == original_val
30
+ expect(data).to eql(original_val)
23
31
  end
24
32
  end
25
33
 
@@ -32,11 +40,11 @@ describe WithTimedCache do
32
40
  i == 0 ? original_val : updated_val
33
41
  end
34
42
  if i == 0
35
- data.should == original_val
43
+ expect(data).to eql(original_val)
36
44
  sleep 1.5 # sleep longer than max_age
37
45
  end
38
46
  end
39
- data.should == updated_val
47
+ expect(data).to eql(updated_val)
40
48
  end
41
49
 
42
50
  it "caches marshaled data to a file" do
@@ -45,11 +53,11 @@ describe WithTimedCache do
45
53
  data = [1, 2, 3]
46
54
 
47
55
  cached_data = with_timed_cache(key, location: @cache_directory) { data }
48
- cached_data.should == data
49
- File.exists?(File.join(@cache_directory, filename)).should be_true
56
+ expect(cached_data).to eql(data)
57
+ expect(File.exists?(File.join(@cache_directory, filename))).to be true
50
58
 
51
59
  raw_cache_data = File.read(File.join(@cache_directory, filename))
52
- Marshal.load(raw_cache_data).should == data
60
+ expect(Marshal.load(raw_cache_data)).to eql(data)
53
61
  end
54
62
 
55
63
  it "lets you store cache data as json" do
@@ -59,11 +67,11 @@ describe WithTimedCache do
59
67
  data = { foo: 'bar', baz: 'qux' }
60
68
 
61
69
  cached_data = with_timed_cache(key, location: @cache_directory, format: :json) { data }
62
- cached_data.should == data
63
- File.exists?(filepath).should be_true
70
+ expect(cached_data).to eql(data)
71
+ expect(File.exists?(filepath)).to be true
64
72
 
65
73
  raw_cache_data = File.read(filepath)
66
- JSON.parse(raw_cache_data, symbolize_names: true).should == data
74
+ expect(JSON.parse(raw_cache_data, symbolize_names: true)).to eql(data)
67
75
  end
68
76
 
69
77
  it "lets you store cache data as yaml" do
@@ -73,11 +81,11 @@ describe WithTimedCache do
73
81
  data = { foo: 'bar', baz: 'qux' }
74
82
 
75
83
  cached_data = with_timed_cache(key, location: @cache_directory, format: :yaml) { data }
76
- cached_data.should == data
77
- File.exists?(filepath).should be_true
84
+ expect(cached_data).to eql(data)
85
+ expect(File.exists?(filepath)).to be true
78
86
 
79
87
  raw_cache_data = File.read(filepath)
80
- YAML.load_file(filepath).should == data
88
+ expect(YAML.load_file(filepath)).to eql(data)
81
89
  end
82
90
 
83
91
  it "returns last cached data if present when an exception is raised" do
@@ -93,14 +101,14 @@ describe WithTimedCache do
93
101
  end
94
102
  sleep 1.5 if i == 0
95
103
  end
96
- data.should == string
104
+ expect(data).to eql(string)
97
105
  end
98
106
 
99
107
  it "returns nil when an exception is raised if no previous cache is present" do
100
108
  data = with_timed_cache(:exception_nil, location: @cache_directory, max_age: 1.second) do
101
109
  raise Exception
102
110
  end
103
- data.should be_nil
111
+ expect(data).to be nil
104
112
  end
105
113
 
106
114
  def clean_cache_directory
@@ -19,9 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
24
- spec.add_development_dependency "guard-rspec"
25
- spec.add_dependency "activesupport"
26
- spec.add_dependency "json"
22
+ spec.add_development_dependency "rake", "~> 10.3"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "guard-rspec", "~> 4.3"
25
+ spec.add_development_dependency "pry-byebug", "~> 2.0"
26
+ spec.add_dependency "activesupport", "~> 4.1"
27
+ spec.add_dependency "json", "~> 1.8"
27
28
  end
metadata CHANGED
@@ -1,99 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_timed_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Stephens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-14 00:00:00.000000000 Z
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
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
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: guard-rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '4.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '4.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: activesupport
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - '>='
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: '4.1'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - '>='
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: '4.1'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: json
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - '>='
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: '1.8'
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - '>='
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: '1.8'
97
111
  description: A simple time based cache
98
112
  email:
99
113
  - iam@jordanstephens.net
@@ -101,7 +115,8 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
- - .gitignore
118
+ - ".gitignore"
119
+ - ".travis.yml"
105
120
  - Gemfile
106
121
  - Guardfile
107
122
  - LICENSE.txt
@@ -113,12 +128,12 @@ files:
113
128
  - lib/with_timed_cache/json_cache.rb
114
129
  - lib/with_timed_cache/version.rb
115
130
  - lib/with_timed_cache/yaml_cache.rb
116
- - spec/lib/with_timed_cache/cache_spec.rb
117
- - spec/lib/with_timed_cache/caches_spec.rb
118
- - spec/lib/with_timed_cache/json_cache_spec.rb
119
- - spec/lib/with_timed_cache/yaml_cache_spec.rb
120
- - spec/lib/with_timed_cache_spec.rb
121
131
  - spec/spec_helper.rb
132
+ - spec/with_timed_cache/cache_spec.rb
133
+ - spec/with_timed_cache/caches_spec.rb
134
+ - spec/with_timed_cache/json_cache_spec.rb
135
+ - spec/with_timed_cache/yaml_cache_spec.rb
136
+ - spec/with_timed_cache_spec.rb
122
137
  - with_timed_cache.gemspec
123
138
  homepage: ''
124
139
  licenses:
@@ -130,25 +145,25 @@ require_paths:
130
145
  - lib
131
146
  required_ruby_version: !ruby/object:Gem::Requirement
132
147
  requirements:
133
- - - '>='
148
+ - - ">="
134
149
  - !ruby/object:Gem::Version
135
150
  version: '0'
136
151
  required_rubygems_version: !ruby/object:Gem::Requirement
137
152
  requirements:
138
- - - '>='
153
+ - - ">="
139
154
  - !ruby/object:Gem::Version
140
155
  version: '0'
141
156
  requirements: []
142
157
  rubyforge_project:
143
- rubygems_version: 2.0.0
158
+ rubygems_version: 2.2.2
144
159
  signing_key:
145
160
  specification_version: 4
146
161
  summary: Cache data to a local file for a defined amount of time
147
162
  test_files:
148
- - spec/lib/with_timed_cache/cache_spec.rb
149
- - spec/lib/with_timed_cache/caches_spec.rb
150
- - spec/lib/with_timed_cache/json_cache_spec.rb
151
- - spec/lib/with_timed_cache/yaml_cache_spec.rb
152
- - spec/lib/with_timed_cache_spec.rb
153
163
  - spec/spec_helper.rb
164
+ - spec/with_timed_cache/cache_spec.rb
165
+ - spec/with_timed_cache/caches_spec.rb
166
+ - spec/with_timed_cache/json_cache_spec.rb
167
+ - spec/with_timed_cache/yaml_cache_spec.rb
168
+ - spec/with_timed_cache_spec.rb
154
169
  has_rdoc: