scash 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scash/version.rb +1 -1
- data/lib/scash.rb +1 -2
- data/test/test_scash.rb +2 -34
- 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: 0bffa41de0ca678f84bac31ff66ebb2f48530aa0
|
4
|
+
data.tar.gz: 0efbb1eb55d831f2a7c0b3cc360c4c5829b96028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ad99565ef44a2dd563f5ffc913bea426d47f7e7745fe429062dbb6e7ed58c35b87936435800b1bac13ddc3a4819f52373b57d428a569860243422b846fcf771
|
7
|
+
data.tar.gz: 58df8c537d1285e48d262a99c161b8f59c94adf784a82927a732fd3a5995c8f209509dc40d0dcedda5652304f013dd734a21869203338f9c20596cadcaf4ffbc
|
data/lib/scash/version.rb
CHANGED
data/lib/scash.rb
CHANGED
@@ -48,6 +48,7 @@ class Scash
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def define_global_variables(variables)
|
51
|
+
@stack.each{|hash|variables.keys.each{|key| hash.delete(key)}}
|
51
52
|
global_variables.merge! convert(variables)
|
52
53
|
build!
|
53
54
|
end
|
@@ -64,8 +65,6 @@ class Scash
|
|
64
65
|
|
65
66
|
def build_hash(stack_index = 0)
|
66
67
|
@stack[stack_index..-1].each_with_index.inject(@klass.new) do |hash, (variables, index)|
|
67
|
-
last = stack_index + index == @stack.size-1
|
68
|
-
variables = variables.reject{|key, value| variables[key].nil? && !last && @stack.last.key?(key) }
|
69
68
|
variables.merge hash
|
70
69
|
end
|
71
70
|
end
|
data/test/test_scash.rb
CHANGED
@@ -147,39 +147,7 @@ describe Scash do
|
|
147
147
|
assert_equal 1337, scash[:result]
|
148
148
|
end
|
149
149
|
|
150
|
-
it "
|
151
|
-
# initial values can never be overwritten with a global-variable, except nil values
|
152
|
-
scash = Scash.new(:initial_a => 1337, :initial_b => nil)
|
153
|
-
scash.with({:a => 1, :b => nil}) do
|
154
|
-
assert_equal [1337, nil, 1, nil], scash.values
|
155
|
-
assert_equal 1337, scash[:initial_a]
|
156
|
-
assert_equal nil, scash[:initial_b]
|
157
|
-
|
158
|
-
scash.define_global_variables :a => "global a", :b => "global b", :c => nil
|
159
|
-
scash.define_global_variables :initial_a => "new a", :initial_b => "new b"
|
160
|
-
|
161
|
-
assert_equal({"a"=>1, "b"=>"global b", "c"=>nil, "initial_a"=>1337, "initial_b"=>"new b"}, scash.to_hash)
|
162
|
-
|
163
|
-
scash.with(:a => "a", :b => nil, :c => nil) do
|
164
|
-
assert_equal({"a" => "a", "b" => "global b", "c" => nil, "initial_a" => 1337, "initial_b" => "new b"}, scash.to_hash)
|
165
|
-
assert_equal "a", scash[:a]
|
166
|
-
assert_equal "global b", scash[:b]
|
167
|
-
assert_equal nil, scash[:c]
|
168
|
-
end
|
169
|
-
|
170
|
-
assert_equal 1, scash[:a]
|
171
|
-
assert_equal "global b", scash[:b]
|
172
|
-
assert_equal 1337, scash[:initial_a]
|
173
|
-
assert_equal "new b", scash[:initial_b]
|
174
|
-
end
|
175
|
-
assert_equal "global a", scash[:a]
|
176
|
-
assert_equal "global b", scash[:b]
|
177
|
-
|
178
|
-
assert_equal 1337, scash[:initial_a]
|
179
|
-
assert_equal "new b", scash[:initial_b]
|
180
|
-
end
|
181
|
-
|
182
|
-
it "overwrites a global variable with same name" do
|
150
|
+
it "overwrites earlier defined variables with same name" do
|
183
151
|
scash = Scash.new
|
184
152
|
scash.with({:a => 1}) do
|
185
153
|
scash.define_global_variables :result => 1337
|
@@ -190,7 +158,7 @@ describe Scash do
|
|
190
158
|
assert_equal 2, scash[:b]
|
191
159
|
scash.define_global_variables :result => "foo"
|
192
160
|
scash.define_global_variables :b => "bar"
|
193
|
-
assert_equal
|
161
|
+
assert_equal "bar", scash[:b]
|
194
162
|
assert_equal "foo", scash[:result]
|
195
163
|
end
|
196
164
|
|