super_stack 1.0.0 → 1.0.1

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: 2ee62f30bb0b8ce359573f8d0c8de39392a866c3
4
- data.tar.gz: 186733047be8988e51c76c09801d6ac93844b634
3
+ metadata.gz: 091053766ee781aa79aec23344855617d62b8f15
4
+ data.tar.gz: 6150e5f5a8ba4610d60c7e800de1e8e58a76c97b
5
5
  SHA512:
6
- metadata.gz: 43db4607abd8d83241a3fb2645ec2969d3ba2e067016e31046d0ef339081fc564d99df14354d6fba6191f294d91dc45f5b4b9e2388b426086ea53dc1fe80728f
7
- data.tar.gz: 67c73bd1935eccaa33ff4dbe0c634ae2339eeb0cfc9a7798330bfd541974f71419be0dd1b518d9e9dc59bfd31549bbd26f83b96c0eeea9806dca2fadb1b80040
6
+ metadata.gz: b6304ed0df60f35bd30d1f3dbb62a509245a1a3387d6ae83dd60f0e47a8012f5b80e8a7e8af089c81c4b88a558ba961b0faceb1749d4508750e7a16c2dcbd029
7
+ data.tar.gz: df871c2bd0b6165fff4bb242df69852bdba761b52a2628726671764cc3acc51084afc6b70367fa5d6dd4ce153e05e2bc231e326839c5161412ea9fdeec269d0a
data/README.md CHANGED
@@ -57,13 +57,13 @@ puts manager.layers.class # => Hash
57
57
  :warning: Versions prior to `1.0.0` were trying to give an indifferent access to the merged hash for strings
58
58
  and symbols, ie `manager[:an_entry]` was giving the same result as `manager['an_entry']`.
59
59
 
60
- This is clearly wrong and not consistent everywhere.
60
+ This is clearly wrong and not consistent everywhere (only valid for the 'root' nodes).
61
61
  __Starting with version `1.0.0` this is no more the case__. Nevertheless a compatibility mode is provided for
62
62
  applications relying on the legacy mechanism, you just need to do:
63
63
 
64
64
  ```ruby
65
65
  require 'super_stack'
66
- SuperStack.set_compatibility_mode
66
+ SuperStack.compatibility_mode = true
67
67
  ```
68
68
  or alternatively, you can do:
69
69
 
@@ -3,7 +3,6 @@ module SuperStack
3
3
 
4
4
  module LayerWrapper
5
5
 
6
- private
7
6
 
8
7
  def load_from_yaml(file_name)
9
8
  begin
@@ -25,7 +25,7 @@ module SuperStack
25
25
  if filter.nil?
26
26
  res.to_hash
27
27
  else
28
- res[filter]
28
+ res[filter.to_s]
29
29
  end
30
30
  end
31
31
 
@@ -0,0 +1,11 @@
1
+ module SuperStack
2
+
3
+ def self.compatibility_mode=(mode)
4
+ @compatibility_mode = mode
5
+ end
6
+
7
+ def self.compatibility_mode
8
+ @compatibility_mode
9
+ end
10
+
11
+ end
@@ -1,7 +1,11 @@
1
1
  module SuperStack
2
2
  class Layer < Hash
3
3
 
4
- include LayerWrapper
4
+ include SuperStack::LayerWrapper
5
5
 
6
+ def initialize(*args)
7
+ super(*args)
8
+ SuperStack::LayerWrapper.from_hash self
9
+ end
6
10
  end
7
11
  end
@@ -71,7 +71,10 @@ module SuperStack
71
71
  end
72
72
 
73
73
  def self.from_hash(hash)
74
- hash.extend self
74
+ class << hash; include SuperStack::LayerWrapper; end
75
+ if SuperStack.compatibility_mode
76
+ class << hash; include SuperStack::Compatibility::LayerWrapper; end
77
+ end
75
78
  end
76
79
 
77
80
  def to_hash
@@ -11,6 +11,7 @@ module SuperStack
11
11
  attr_reader :layers, :write_layer
12
12
 
13
13
  def initialize
14
+ self.extend SuperStack::Compatibility::Manager if SuperStack.compatibility_mode
14
15
  @layers = {}
15
16
  self.default_merge_policy = DEFAULT_MERGE_POLICY
16
17
  end
@@ -1,3 +1,3 @@
1
1
  require 'super_stack'
2
2
 
3
- SuperStack.set_compatibility_mode
3
+ SuperStack.compatibility_mode = true
@@ -1,3 +1,3 @@
1
1
  module SuperStack
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/lib/super_stack.rb CHANGED
@@ -1,22 +1,9 @@
1
1
  require 'super_stack/version'
2
+ require 'super_stack/compatibility/switch'
2
3
  require 'super_stack/merge_policies'
3
4
  require 'super_stack/layer_wrapper'
4
5
  require 'super_stack/layer'
5
6
  require 'super_stack/manager'
7
+ require 'super_stack/compatibility/layer_wrapper'
8
+ require 'super_stack/compatibility/manager'
6
9
 
7
- module SuperStack
8
-
9
- def self.set_compatibility_mode
10
- require 'super_stack/compatibility/layer_wrapper'
11
- require 'super_stack/compatibility/manager'
12
-
13
- SuperStack::Manager.class_eval do
14
- include SuperStack::Compatibility::Manager
15
- end
16
-
17
- SuperStack::LayerWrapper.module_eval do
18
- include SuperStack::Compatibility::LayerWrapper
19
- end
20
- end
21
-
22
- end
data/spec/layer_spec.rb CHANGED
@@ -10,7 +10,7 @@ describe SuperStack::Layer do
10
10
  end
11
11
 
12
12
  it 'has a default name' do
13
- expect(subject.name == subject.class.const_get('DEFAULT_LAYER_NAME')).to be_truthy
13
+ expect(subject.name).not_to be_empty
14
14
  end
15
15
 
16
16
  it 'should have an auto-reload flag' do
data/spec/manager_spec.rb CHANGED
@@ -73,8 +73,8 @@ describe SuperStack::Manager do
73
73
  expect {subject.add_layer({}) }.not_to raise_error
74
74
  expect {subject.add_layer({}) }.not_to raise_error
75
75
  expect(subject.layers.keys.count == 2).to be_truthy
76
- expect(subject.layers.keys[0] == SuperStack::Layer::DEFAULT_LAYER_NAME).to be_truthy
77
- expect(subject.layers.keys[1] == "#{SuperStack::Layer::DEFAULT_LAYER_NAME} #2").to be_truthy
76
+ expect(subject.layers.keys[0] == SuperStack::LayerWrapper::DEFAULT_LAYER_NAME).to be_truthy
77
+ expect(subject.layers.keys[1] == "#{SuperStack::LayerWrapper::DEFAULT_LAYER_NAME} #2").to be_truthy
78
78
  end
79
79
 
80
80
  it 'should provide a dynamic merge' do
@@ -97,6 +97,13 @@ describe SuperStack::Manager do
97
97
  expect {subject[:foo] = :bar}.to raise_error
98
98
  end
99
99
 
100
+
101
+ it 'should differentiate symbols from strings' do
102
+ subject << layer1
103
+ expect(subject[:layer]).not_to eq subject['layer']
104
+ end
105
+
106
+
100
107
  context 'when specifying a write layer' do
101
108
 
102
109
  it 'should be possible using its name or itself' do
@@ -305,4 +312,31 @@ describe SuperStack::Manager do
305
312
 
306
313
  end
307
314
 
315
+
316
+ context 'when using compatibility mode' do
317
+
318
+ before(:all) do
319
+ SuperStack.compatibility_mode = true
320
+ end
321
+
322
+ after(:all) do
323
+ SuperStack.compatibility_mode = false
324
+ end
325
+
326
+ subject {
327
+ s = SuperStack::Manager.new
328
+ s.add_layer layer1
329
+ s
330
+ }
331
+
332
+ it 'should not differentiate symbols from strings (for root nodes)' do
333
+ expect(subject[:layer]).to eq subject['layer']
334
+ end
335
+
336
+ it 'should differentiate symbols from strings (for non root nodes)' do
337
+ expect(subject['to-be-merged'][:name]).not_to eq subject['to-be-merged']['name']
338
+ end
339
+
340
+ end
341
+
308
342
  end
data/spec/spec_helper.rb CHANGED
@@ -16,7 +16,6 @@
16
16
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
17
 
18
18
  require 'super_stack'
19
- SuperStack.set_compatibility_mode
20
19
 
21
20
 
22
21
  def file_from_layer(layer_number)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent B.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-10 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,6 +112,7 @@ files:
112
112
  - lib/super_stack.rb
113
113
  - lib/super_stack/compatibility/layer_wrapper.rb
114
114
  - lib/super_stack/compatibility/manager.rb
115
+ - lib/super_stack/compatibility/switch.rb
115
116
  - lib/super_stack/layer.rb
116
117
  - lib/super_stack/layer_wrapper.rb
117
118
  - lib/super_stack/manager.rb