arcanus 0.5.0 → 0.6.0
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 +4 -4
- data/lib/arcanus/chest.rb +24 -42
- data/lib/arcanus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f691ad3164c5ba4a261d2d974d4095b480c739d
|
4
|
+
data.tar.gz: 22682f983ddb043dcf11e01abd60ee76ebe2fae2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee13797a980e9f9a2afd541884a3d814a2e4348aa953657ddb29ec6684f9bdb68a5df5d00dea7c07c56284d7c565f52486870fc3e2b7b81baf555f69d449805b
|
7
|
+
data.tar.gz: 168b42e29bca5d5b8c6280880e074316802e1c936f41a7f45011ec141f0ecb8cc007af7a91b7ebe9e57aec24f8670c03b126a312c16fdbc279606edb303a0f5d
|
data/lib/arcanus/chest.rb
CHANGED
@@ -21,39 +21,28 @@ module Arcanus
|
|
21
21
|
# @param key [String]
|
22
22
|
# @return [Object]
|
23
23
|
def [](key)
|
24
|
-
@hash
|
25
|
-
|
26
|
-
|
27
|
-
# Fetch key from the chest as if it were a hash.
|
28
|
-
def fetch(*args)
|
29
|
-
@hash.fetch(*args)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns the contents of the chest as a hash.
|
33
|
-
def contents
|
34
|
-
@hash
|
35
|
-
end
|
36
|
-
|
37
|
-
# Provides access to chest items using regular method calls instead of hash
|
38
|
-
# accesses.
|
39
|
-
def method_missing(method_sym, *)
|
40
|
-
method_name = method_sym.to_s
|
41
|
-
if @hash.key?(method_name)
|
42
|
-
value = @hash[method_name]
|
24
|
+
if @hash.key?(key)
|
25
|
+
value = @hash[key]
|
43
26
|
if value.is_a?(Hash)
|
44
|
-
Item.new(value, [
|
27
|
+
Item.new(value, [key])
|
45
28
|
else
|
46
29
|
value
|
47
30
|
end
|
48
31
|
else
|
49
32
|
raise KeyError,
|
50
|
-
"Key '#{
|
33
|
+
"Key '#{key}' does not exist in this Arcanus chest",
|
51
34
|
caller
|
52
35
|
end
|
53
36
|
end
|
54
37
|
|
55
|
-
|
56
|
-
|
38
|
+
# Fetch key from the chest as if it were a hash.
|
39
|
+
def fetch(*args)
|
40
|
+
@hash.fetch(*args)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the contents of the chest as a hash.
|
44
|
+
def contents
|
45
|
+
@hash
|
57
46
|
end
|
58
47
|
|
59
48
|
# Set value for the specified key path.
|
@@ -189,40 +178,33 @@ module Arcanus
|
|
189
178
|
# Helper class for returning contents nested hashes, exposing helpers to
|
190
179
|
# access them via method calls.
|
191
180
|
class Item
|
192
|
-
def initialize(hash, prefix
|
181
|
+
def initialize(hash, prefix)
|
193
182
|
@hash = hash
|
194
183
|
@prefix = prefix
|
195
184
|
end
|
196
185
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
186
|
+
# Access the item as if it were a hash.
|
187
|
+
#
|
188
|
+
# This will raise an error if the key does not exist, however.
|
189
|
+
#
|
190
|
+
# @param key [String]
|
191
|
+
# @return [Object]
|
192
|
+
def [](key)
|
193
|
+
if @hash.key?(key)
|
194
|
+
value = @hash[key]
|
201
195
|
if value.is_a?(Hash)
|
202
|
-
Item.new(value, @prefix + [
|
196
|
+
Item.new(value, @prefix + [key])
|
203
197
|
else
|
204
198
|
value
|
205
199
|
end
|
206
200
|
else
|
207
|
-
key_name = "#{@prefix.join('.')}.#{
|
201
|
+
key_name = "#{@prefix.join('.')}.#{key}"
|
208
202
|
raise KeyError,
|
209
203
|
"Key '#{key_name}' does not exist in this Arcanus chest",
|
210
204
|
caller
|
211
205
|
end
|
212
206
|
end
|
213
207
|
|
214
|
-
def respond_to?(method_sym, include_private = false)
|
215
|
-
@hash.key?(method_sym.to_s) || super
|
216
|
-
end
|
217
|
-
|
218
|
-
# Access the item as if it were a hash.
|
219
|
-
#
|
220
|
-
# @param key [String]
|
221
|
-
# @return [Object]
|
222
|
-
def [](key)
|
223
|
-
@hash[key]
|
224
|
-
end
|
225
|
-
|
226
208
|
# Fetch key from the chest as if it were a hash.
|
227
209
|
def fetch(*args)
|
228
210
|
@hash.fetch(*args)
|
data/lib/arcanus/version.rb
CHANGED