delorean_lang 0.4.8 → 0.5.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: 3a6eb15c510767db6fe200846f73c99332074552
4
- data.tar.gz: a088e3928a4646f276f23f144e05fb1ed5d2717b
3
+ metadata.gz: 89298e290f313ade46bf260e446224804149a46f
4
+ data.tar.gz: d31f413b2c391b0d98b157967693be82b86bf101
5
5
  SHA512:
6
- metadata.gz: 542634f338cb3af160f4a333548cbb65bd98337d6ea5cce30176c27dd7c574bdb4ce84bb0e5e5f0a4160e55a5ba01fa52533e4b41c4cb87d6bcec5d7949413d9
7
- data.tar.gz: 6f13545b0fe049fd9d8ee461eab5047c8f1b0d446207751f0c10f3a10dcdcc89778f18045953e4394bce159a23122470de269b80682fea0fa50814f31d6f6478
6
+ metadata.gz: 0c19fce0e9ab539d9b95c9491c3b04e6711c1617a79fb1a4c1ae3aa6895d831809d018cc1aa52385403c5c7c7ebd2d8474ba004fa9595d6f55d2c895f0e01644
7
+ data.tar.gz: 24056448d59d6ed59dfed9f8a28c89c8c9aba471f0e9d5097263f1e33eefaf7d73a8e699f853b1a7bcd54d3a49b80ba02ff1a9c3c2b61305a2994ab0a0b38f88
data/README.md CHANGED
@@ -196,7 +196,7 @@ Delorean expects it to have methods with following signatures:
196
196
  ```ruby
197
197
 
198
198
  cache_item(klass:, cache_key:, item:)
199
- fetch_item(klass:, cache_key:)
199
+ fetch_item(klass:, cache_key:, default:)
200
200
  cache_key(klass:, method_name:, args:)
201
201
  clear!(klass:)
202
202
  clear_all!
@@ -17,8 +17,12 @@ module Delorean
17
17
  lookup_cache[klass][cache_key] = item
18
18
  end
19
19
 
20
- def fetch_item(klass:, cache_key:)
21
- lookup_cache.dig(klass, cache_key)
20
+ def fetch_item(klass:, cache_key:, default: nil)
21
+ subh = lookup_cache.fetch(klass, default)
22
+ return default if subh == default
23
+ v = subh.fetch(cache_key, default)
24
+ return default if v == default
25
+ v
22
26
  end
23
27
 
24
28
  def cache_key(klass:, method_name:, args:)
@@ -45,10 +45,10 @@ module Delorean
45
45
  klass: self, method_name: name, args: args
46
46
  )
47
47
  cached_item = delorean_cache_adapter.fetch_item(
48
- klass: self, cache_key: cache_key
48
+ klass: self, cache_key: cache_key, default: :NF
49
49
  )
50
50
 
51
- next cached_item if cached_item
51
+ next cached_item if cached_item != :NF
52
52
 
53
53
  res = block.call(*args)
54
54
 
@@ -1,3 +1,3 @@
1
1
  module Delorean
2
- VERSION = "0.4.8"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -44,15 +44,20 @@ describe "Delorean cache" do
44
44
  Dummy.returns_cached_openstruct(t, t)
45
45
  end
46
46
 
47
+ item_2 = ::Delorean::Cache.adapter.fetch_item(
48
+ klass: Dummy, cache_key: [:returns_cached_openstruct, 2, 2], default: :NF
49
+ )
50
+ expect(item_2).to eq(:NF)
47
51
  item_2 = ::Delorean::Cache.adapter.fetch_item(
48
52
  klass: Dummy, cache_key: [:returns_cached_openstruct, 2, 2]
49
53
  )
54
+ expect(item_2).to eq(nil)
50
55
 
51
- item_10 = ::Delorean::Cache.adapter.fetch_item(
52
- klass: Dummy, cache_key: [:returns_cached_openstruct, 10, 10]
56
+ item_10, item_10_found = ::Delorean::Cache.adapter.fetch_item(
57
+ klass: Dummy, cache_key: [:returns_cached_openstruct, 10, 10], default: :NF
53
58
  )
54
59
 
55
- expect(item_2).to_not be_present
56
- expect(item_10).to be_present
60
+ expect(item_10).to be_a(OpenStruct)
61
+ expect(item_10["10"]).to eq(10)
57
62
  end
58
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delorean_lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-09 00:00:00.000000000 Z
11
+ date: 2019-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop