scash 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scash.rb +15 -8
- data/lib/scash/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: 4d4027b8c16c80e55adc1684995a68ae3845e37b
|
4
|
+
data.tar.gz: dba5b4f126fe90764752c77fe622460c8c06d93e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53430248c797466b5e5de7d09a44c84c7b92ce231560b9d332658e423cf30d8d1424dac3f18c30b3ace8459fbbef48721b0171aef488ba7e4335fca721458d8a
|
7
|
+
data.tar.gz: 8d47354d191d0ef4d67d7f403b64e41a2041d21c019d05a54af95dd3da1033d02e50c1281be16fa303234b84620962da573f6a0bd50579e0f28f60286f3bbe3a
|
data/lib/scash.rb
CHANGED
@@ -10,20 +10,19 @@ class Scash
|
|
10
10
|
|
11
11
|
attr_reader :stack
|
12
12
|
|
13
|
-
def initialize(variables =
|
13
|
+
def initialize(variables = nil, klass = HashWithIndifferentAccess)
|
14
14
|
@klass = klass
|
15
|
-
@stack = [convert(variables)]
|
16
|
-
@hashes = [build_hash]
|
17
|
-
@inverse_hashes = [build_inverse_hash]
|
18
|
-
@global_variables = {}
|
15
|
+
@stack = variables ? [convert(variables)] : []
|
16
|
+
@hashes = variables ? [build_hash] : []
|
17
|
+
@inverse_hashes = variables ? [build_inverse_hash] : []
|
19
18
|
end
|
20
19
|
|
21
20
|
def to_hash
|
22
|
-
@hashes.first.merge(
|
21
|
+
any? ? @hashes.first.merge(global_variables) : global_variables
|
23
22
|
end
|
24
23
|
|
25
24
|
def to_inverse_hash
|
26
|
-
@inverse_hashes.first.merge(
|
25
|
+
any? ? @inverse_hashes.first.merge(global_variables) : global_variables
|
27
26
|
end
|
28
27
|
|
29
28
|
def scope(variables)
|
@@ -54,11 +53,19 @@ class Scash
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def define_global_variables(variables)
|
57
|
-
|
56
|
+
global_variables.merge! convert(variables)
|
58
57
|
end
|
59
58
|
|
60
59
|
private
|
61
60
|
|
61
|
+
def global_variables
|
62
|
+
@global_variables ||= @klass.new
|
63
|
+
end
|
64
|
+
|
65
|
+
def any?
|
66
|
+
@stack.any?
|
67
|
+
end
|
68
|
+
|
62
69
|
def build_hash(index = 0)
|
63
70
|
@stack[index..-1].inject(@klass.new) do |hash, variables|
|
64
71
|
variables.merge hash
|
data/lib/scash/version.rb
CHANGED