scash 0.1.0 → 0.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/scash.rb +15 -8
  3. data/lib/scash/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eab17874bb39585b1908492ff3167973886daa1a
4
- data.tar.gz: 8d79365ffce1fb0712e2dbdb0d196e87f165f558
3
+ metadata.gz: 4d4027b8c16c80e55adc1684995a68ae3845e37b
4
+ data.tar.gz: dba5b4f126fe90764752c77fe622460c8c06d93e
5
5
  SHA512:
6
- metadata.gz: 4b648c6503c28de69b49dfdd2876d0954481ad61aceceeb66995c453abfb669182de5d68671c99158711a6c5854a95de8b68344ac2c9a7a13283568947aab60f
7
- data.tar.gz: a20b50700b57ef2d86ea35ac172685de49210a858151a38fb83861949a1ee4a13f2bd1814e4cac86c1ddcd62c36712afbfaa6ad02365ff782fee181ae3806983
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 = {}, klass = HashWithIndifferentAccess)
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(@global_variables)
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(@global_variables)
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
- @global_variables.merge! convert(variables)
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
@@ -1,3 +1,3 @@
1
1
  class Scash
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Kaag