atomic_cache 0.2.0.rc1 → 0.2.0.rc2

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
  SHA256:
3
- metadata.gz: 4534d927a8015f910a8f6a330f5a49ffc2e96931b968bdafe123c104f50ee159
4
- data.tar.gz: c8b834855c70ae59b272efd57eb9f491db734b90280a3d20f14ba4b56fe26786
3
+ metadata.gz: d908f524b778436fea47a5a576f1f64003d6640ff734ce61aa711d4432fb2cac
4
+ data.tar.gz: 7fa480b5bd764c4f4b5e2d6a940e42fbccc4900bd892e8a6578d76389cafc09d
5
5
  SHA512:
6
- metadata.gz: d1f49452ff1cf04f665112f39232749ec595bb6ac3a45f13ee178d52fe0e9581e594466f2936e542495f6dfda5b665617a77aebbd70e320b7a137d551fe1bf13
7
- data.tar.gz: 113adcfe789cd195283c3bf2db1691c0724cf2b9e9fb5d1e3ac13bc93d401faac47b6206c54e8da045d666d27c913f617e931aa77e18b7f36c7a39b9cc2a41db
6
+ metadata.gz: 19a87c2ef28d260290edf004559611228cbf79d378814db31d6d1ffb24399b118bdff8c66d3049ae7c8f028039b5606b1abe80d72726406eae759c301639a4d4
7
+ data.tar.gz: e18ea892a4eb44e0fb851d0e5aae5aa81adf2443507e8dd4e2c9273342759db1d277f27a00444dd9e8b970783927481c60f1c67c08d1639af7f7139e09679be1
@@ -100,7 +100,7 @@ module AtomicCache
100
100
  end
101
101
 
102
102
  def expire_cache(at=Time.now)
103
- self.class.expire_cache(ns)
103
+ self.class.expire_cache(at)
104
104
  end
105
105
 
106
106
  def last_modified_time
@@ -20,11 +20,11 @@ module AtomicCache
20
20
  # @param separator [String] character or string to separate keyspace segments
21
21
  # @param timestamp_formatter [Proc] function to turn Time -> String
22
22
  def initialize(namespace:, root: nil, separator: nil, timestamp_formatter: nil)
23
+ @timestamp_formatter = timestamp_formatter || DefaultConfig.instance.timestamp_formatter
24
+ @separator = separator || DefaultConfig.instance.separator
23
25
  @namespace = []
24
26
  @namespace = normalize_segments(namespace) if namespace.present?
25
- @separator = separator || DefaultConfig.instance.separator
26
- @timestamp_formatter = timestamp_formatter || DefaultConfig.instance.timestamp_formatter
27
- @root = root || namespace.last
27
+ @root = root || @namespace.last
28
28
  end
29
29
 
30
30
  # Create a new Keyspace, extending the namespace with the given segments and
@@ -70,7 +70,7 @@ module AtomicCache
70
70
  def normalize_segments(segments)
71
71
  if segments.is_a? Array
72
72
  segments.map { |seg| expand_segment(seg) }
73
- elsif sgs.nil?
73
+ elsif segments.nil?
74
74
  []
75
75
  else
76
76
  [expand_segment(segments)]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AtomicCache
4
- VERSION = "0.2.0.rc1"
4
+ VERSION = "0.2.0.rc2"
5
5
  end
@@ -82,6 +82,13 @@ describe 'AtomicCacheConcern' do
82
82
  expect(ns2_value).to eq('new-buz')
83
83
  end
84
84
  end
85
+
86
+ it 'works on the instance method' do
87
+ time = Time.local(2018, 1, 1, 15, 30, 0)
88
+ subject.new.expire_cache(time)
89
+ expect(key_storage.store).to have_key(:'foo1:lmt')
90
+ expect(key_storage.read(:'foo1:lmt')).to eq(time.to_i)
91
+ end
85
92
  end
86
93
 
87
94
  context '#cache_keyspace' do
@@ -6,29 +6,48 @@ describe 'Keyspace' do
6
6
  subject { AtomicCache::Keyspace.new(namespace: ['foo', 'bar'], root: 'foo') }
7
7
 
8
8
  context '#initialize' do
9
- it 'hashes non-primitive types' do
10
- ids = [1,2,3]
11
- ns1 = AtomicCache::Keyspace.new(namespace: ['foo', ids])
12
- hash = ns1.send(:hexhash, ids)
13
- expect(ns1.namespace).to eq(['foo', hash])
14
- end
15
9
 
16
- it 'leaves primitives alone' do
17
- ns1 = AtomicCache::Keyspace.new(namespace: ['foo', :foo, 5])
18
- expect(ns1.namespace).to eq(['foo', :foo, 5])
10
+ it 'sorts sortable values before hashing' do
11
+ ks1 = AtomicCache::Keyspace.new(namespace: ['foo', [1, 2, 3]])
12
+ ks2 = AtomicCache::Keyspace.new(namespace: ['foo', [3, 2, 1]])
13
+ expect(ks1.namespace).to eq(ks2.namespace)
19
14
  end
20
15
 
21
- it 'sorts sortable values before hashing' do
22
- ns1 = AtomicCache::Keyspace.new(namespace: ['foo', [1, 2, 3]])
23
- ns2 = AtomicCache::Keyspace.new(namespace: ['foo', [3, 2, 1]])
24
- expect(ns1.namespace).to eq(ns2.namespace)
16
+ context 'namespace' do
17
+ it 'accepts nil' do
18
+ ks = AtomicCache::Keyspace.new(namespace: nil)
19
+ expect(ks.namespace).to eq([])
20
+ end
21
+
22
+ it 'accepts single values' do
23
+ ks = AtomicCache::Keyspace.new(namespace: 'foo')
24
+ expect(ks.namespace).to eq(['foo'])
25
+ end
26
+
27
+ it 'hashes non-primitive types' do
28
+ ids = [1,2,3]
29
+ ks1 = AtomicCache::Keyspace.new(namespace: ['foo', ids])
30
+ hash = ks1.send(:hexhash, ids)
31
+ expect(ks1.namespace).to eq(['foo', hash])
32
+ end
33
+
34
+ it 'leaves primitives alone' do
35
+ ks1 = AtomicCache::Keyspace.new(namespace: ['foo', :foo, 5])
36
+ expect(ks1.namespace).to eq(['foo', :foo, 5])
37
+ end
38
+
39
+ it 'expands timestamps' do
40
+ formatter = Proc.new { |t| 'formatted' }
41
+ ks = AtomicCache::Keyspace.new(namespace: Time.new, timestamp_formatter: formatter)
42
+ expect(ks.namespace).to eq(['formatted'])
43
+ end
25
44
  end
26
45
  end
27
46
 
28
47
  context '#child' do
29
48
  it 'extends the keyspace' do
30
- ns2 = subject.child([:buz, :baz])
31
- expect(ns2.namespace).to eq(['foo', 'bar', :buz, :baz])
49
+ ks2 = subject.child([:buz, :baz])
50
+ expect(ks2.namespace).to eq(['foo', 'bar', :buz, :baz])
32
51
  end
33
52
  end
34
53
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atomic_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.rc1
4
+ version: 0.2.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ibotta Developers
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-28 00:00:00.000000000 Z
12
+ date: 2018-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler