readthis 1.0.0 → 1.1.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: 985ab4cb70b6ff45de0b279fe4d3ca90690cb206
4
- data.tar.gz: d3c0519b74366c12278dc2a554d0a33c2914e7ac
3
+ metadata.gz: c15a08e16c0c3499ba92207c32a0fb3cd07d6bea
4
+ data.tar.gz: 77b6b856ee036051b59a83c7a2013af49ef4c898
5
5
  SHA512:
6
- metadata.gz: e0cec4bef654487ed5f99c46f27d05572993a823239d1993b6e0b534f0b699f170c773ef191cddf468e1b05936c588d23ac6716ddf7659c89a86710306f13c5b
7
- data.tar.gz: 5f8ac666204946a58135953c5e4b23d64a12f412019d578b28c8b8b1a7c351c1004775c0470a812038b12d2577b87eec5df8a4e09f628e5fbb1bed3fc008517a
6
+ metadata.gz: e1c2bd1bcadb0b1d4636de110c1202adf9f4c197bc189ef5282d86f4765612d5383ec9792d435b0629012732151e5a7468a965cc7d99a8b14e9e95100d6312af
7
+ data.tar.gz: 8ab80c80422fa2ad11d70e03ad6697c6a5d5d78fc76460b27cf1a332b023b9b0419c40020d291cc8db01638844dfe33a693c12a59e1d28474b9f858dc06998cf
@@ -138,6 +138,7 @@ module Readthis
138
138
  # cache.fetch('today', force: true) # => nil
139
139
  #
140
140
  def fetch(key, options = {})
141
+ options ||= {}
141
142
  value = read(key, options) unless options[:force]
142
143
 
143
144
  if value.nil? && block_given?
@@ -351,7 +352,7 @@ module Readthis
351
352
  end
352
353
 
353
354
  def merged_options(options)
354
- (options || {}).merge!(@options)
355
+ @options.merge(options || {})
355
356
  end
356
357
 
357
358
  def pool_options(options)
@@ -0,0 +1,7 @@
1
+ module Readthis
2
+ ReadthisError = Class.new(StandardError)
3
+
4
+ SerializersFrozenError = Class.new(ReadthisError)
5
+ SerializersLimitError = Class.new(ReadthisError)
6
+ UnknownSerializerError = Class.new(ReadthisError)
7
+ end
@@ -1,11 +1,8 @@
1
1
  require 'json'
2
+ require 'readthis/errors'
2
3
  require 'readthis/passthrough'
3
4
 
4
5
  module Readthis
5
- SerializersFrozenError = Class.new(StandardError)
6
- SerializersLimitError = Class.new(StandardError)
7
- UnknownSerializerError = Class.new(StandardError)
8
-
9
6
  class Serializers
10
7
  BASE_SERIALIZERS = {
11
8
  Marshal => 0x1,
@@ -1,3 +1,3 @@
1
1
  module Readthis
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/readthis.rb CHANGED
@@ -1,10 +1,18 @@
1
1
  require 'readthis/cache'
2
+ require 'readthis/errors'
2
3
  require 'readthis/serializers'
3
4
  require 'readthis/version'
4
5
 
5
6
  module Readthis
6
7
  extend self
7
8
 
9
+ # The current, global, instance of serializers that is used by all cache
10
+ # instances.
11
+ #
12
+ # @returns [Readthis::Serializers] An cached Serializers instance
13
+ #
14
+ # @see readthis/serializers
15
+ #
8
16
  def serializers
9
17
  @serializers ||= Readthis::Serializers.new
10
18
  end
@@ -48,11 +48,16 @@ RSpec.describe Readthis::Cache do
48
48
  end
49
49
 
50
50
  it 'uses a custom expiration' do
51
- cache.write('some-key', 'some-value', expires_in: 1)
51
+ cache = Readthis::Cache.new(namespace: 'cache', expires_in: 86400)
52
+
53
+ cache.write('some-key', 'some-value')
54
+ cache.write('other-key', 'other-value', expires_in: 1)
52
55
 
53
56
  expect(cache.read('some-key')).not_to be_nil
57
+ expect(cache.read('other-key')).not_to be_nil
54
58
  sleep 1.01
55
- expect(cache.read('some-key')).to be_nil
59
+ expect(cache.read('some-key')).not_to be_nil
60
+ expect(cache.read('other-key')).to be_nil
56
61
  end
57
62
 
58
63
  it 'expands non-string keys' do
@@ -156,6 +161,11 @@ RSpec.describe Readthis::Cache do
156
161
 
157
162
  expect(cache.read('short-key')).to eq('other stuff')
158
163
  end
164
+
165
+ it 'gets an existing value when `options` are passed as nil' do
166
+ cache.write('great-key', 'great')
167
+ expect(cache.fetch('great-key', nil)).to eq('great')
168
+ end
159
169
  end
160
170
 
161
171
  describe '#read_multi' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readthis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Selbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-05 00:00:00.000000000 Z
11
+ date: 2015-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -120,6 +120,7 @@ files:
120
120
  - lib/readthis.rb
121
121
  - lib/readthis/cache.rb
122
122
  - lib/readthis/entity.rb
123
+ - lib/readthis/errors.rb
123
124
  - lib/readthis/expanders.rb
124
125
  - lib/readthis/passthrough.rb
125
126
  - lib/readthis/serializers.rb