dot_hash 1.1.6 → 1.1.7

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: 3a348ba75c80c353302b1857142a1c41c4e7cee8
4
- data.tar.gz: 9e88b56233a96201a90f0bb6052659fc9188949d
3
+ metadata.gz: a1b95611ef880619871a9f512c8ade7347246066
4
+ data.tar.gz: 649c5672f7b315cd5b340ad72eb9a0a6681970ca
5
5
  SHA512:
6
- metadata.gz: 52ac95b9d2bd388bcb773c032fa2553f0f73b8a127585983d9d22758a5b12ca88b8a9e02af5e212de3759642a45570fee6b0197908b61f8a4e98e9b3173b0d3e
7
- data.tar.gz: 7a83b68221204451034086766eb55910a49f9c3b4ce3a83bcb3e605e9b93753261e77f9e264e606732040a2ec122ba02274d0b6a85c281d443c7a9a4ab2f483c
6
+ metadata.gz: 17e4590a50c2366dd2bc2a24498ab74da204da627d24069012c00250a77c95d1a56939249f2a42f5013ec6d538af9d3838410a0326d112b14c967d6670014eb5
7
+ data.tar.gz: d402862159c8f3d265d181a0d8dbfcdd63773239e4b853576120354a14683ae25d7ca6b3b83aade014ec10e461dd713b0ed7abe8f5e28db015b4800e044090de
@@ -37,17 +37,15 @@ module DotHash
37
37
  end
38
38
 
39
39
  def fetch(key, *args, &block)
40
- key = hash.has_key?(key.to_s) ? key.to_s : key.to_sym
41
- value = hash.fetch(key, *args, &block)
40
+ key_sym = key.to_sym
42
41
 
43
- if value.nil? or hash.respond_to?(key)
44
- hashify_item value
45
- elsif cached.has_key?(key)
46
- value
47
- else
48
- cached[key] = true
49
- hash[key] = hashify_item(value)
42
+ value = cached.fetch(key_sym) do
43
+ key = hash.has_key?(key_sym) ? key_sym : key.to_s
44
+ hashify_item hash.fetch(key, *args, &block)
50
45
  end
46
+
47
+ return value if skip_cache?(key_sym, value)
48
+ cached[key_sym] = value
51
49
  end
52
50
 
53
51
  def has_key?(key)
@@ -59,7 +57,11 @@ module DotHash
59
57
  private
60
58
 
61
59
  def cached
62
- @cached ||= self.class.new({})
60
+ @cached ||= {}
61
+ end
62
+
63
+ def skip_cache?(key, value)
64
+ value.nil? or hash.respond_to?(key) or cached.has_key?(key)
63
65
  end
64
66
 
65
67
  def execute(key, *args, &block)
@@ -5,7 +5,8 @@ module DotHash
5
5
  end
6
6
 
7
7
  def load(*args)
8
- hash.replace Loader.new(hash, *args).hash
8
+ @cached = {}
9
+ @hash = Loader.new(hash, *args).hash
9
10
  end
10
11
 
11
12
  class << self
@@ -1,3 +1,3 @@
1
1
  module DotHash
2
- VERSION = "1.1.6"
2
+ VERSION = "1.1.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dot_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Eden