super_stack 0.0.2 → 0.1.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/README.md +95 -1
- data/lib/super_stack/layer_wrapper.rb +21 -4
- data/lib/super_stack/manager.rb +36 -17
- data/lib/super_stack/merge_policies.rb +12 -0
- data/lib/super_stack/merge_policies/keep_policy.rb +11 -0
- data/lib/super_stack/version.rb +1 -1
- data/spec/layer_spec.rb +33 -5
- data/spec/manager_spec.rb +70 -30
- data/spec/merge_policies_spec.rb +13 -5
- data/spec/spec_helper.rb +9 -0
- data/test/layer_content_type_invalid.yml +10 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a35826dd6aa1c436784d40750be42b5d903a9e8
|
4
|
+
data.tar.gz: 4036c864e855b5a9f420953ef0d99f4e83acbc36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79a519c5e1a9f202ce7ff2d2be502f94adb204a6b6c9e52775e56d6d0c0dd679add921e772c250bafcbba89c925872bbd7d10dc74964231b1e4af91281968579
|
7
|
+
data.tar.gz: b0a89dffd813a711c242498bcda46882c1f3b5dd941fe79056aa423cf57c4bed0888e88946b151af11b312bce2430eceeaf6ca75a1ef21a95fb1f3f61ddf4143
|
data/README.md
CHANGED
@@ -21,7 +21,96 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
|
24
|
+
### Create a manager
|
25
|
+
|
26
|
+
The manager contains your different layers (hashes basically), allows you to set priorities among them, and provides
|
27
|
+
a policy to merge them.
|
28
|
+
|
29
|
+
To use the manager, you just need to:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'super_stack'
|
33
|
+
|
34
|
+
manager = SuperStack::Manager.new
|
35
|
+
```
|
36
|
+
|
37
|
+
This is from the manager, that you will get the result of the merge of the different layers. Use `manager[]` to access
|
38
|
+
the result of the merge of all layers as a hash. It will be done according to the priority the layers have and the merge
|
39
|
+
policy chosen.
|
40
|
+
|
41
|
+
You can directly access to a particular key of the resulting merging by simply doing `manager[:your_key]` like you would
|
42
|
+
do with a hash. (`manager` itself has no `Hash` in its ancestors, whereas `manager[]` *is* actually a `Hash`).
|
43
|
+
|
44
|
+
**None of the layers is modified by the manager**.
|
45
|
+
|
46
|
+
|
47
|
+
### Layers
|
48
|
+
|
49
|
+
Layers are actually simple hashes that include the `SuperStack::LayerWrapper` module. Therefore you can create a layer by
|
50
|
+
different means:
|
51
|
+
|
52
|
+
* by invoking `SuperStack::Layer.new`. You can use you all options you would use on a hash.
|
53
|
+
* by calling `SuperStack::LayerWrapper.from_hash(your_hash)`. That will just add the module `SuperStack::LayerWrapper`
|
54
|
+
to your hash.
|
55
|
+
* by adding manually adding the module to your hash (`your_hash.extend SuperStack::LayerWrapper`), which is strictly
|
56
|
+
equivalent to the previous method.
|
57
|
+
|
58
|
+
When you create a new layer from scratch or by extending your own hash, it has automatically a name assigned, and no
|
59
|
+
particular priority. but as soon as it is added to a manager by doing either `manager << your_hash_or_layer` or
|
60
|
+
`manager.add_layer(your_hash_or_layer)`, it will see its name automatically changed (numbers automatically added) **if
|
61
|
+
the name conflicts with another layer already handled by the manager**.
|
62
|
+
|
63
|
+
You can notice by the way that it gives a third way to create a layer from a hash, as when adding a hash to a manager,
|
64
|
+
it automatically adds the `SuperStack::LayerWrapper` module to the hash.
|
65
|
+
|
66
|
+
Layers can be populated from a file anytime using the `load` method:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
layer = SuperStack::Layer.new.load 'a_file_somewhere'
|
70
|
+
# Once loaded you can get the file name used to load the layed anytime
|
71
|
+
puts layer.file_name
|
72
|
+
# And you can load or reload the layer
|
73
|
+
layer.has_file? # => true
|
74
|
+
layer.load
|
75
|
+
layer.reload
|
76
|
+
```
|
77
|
+
|
78
|
+
On top of this you can reload all the layers which have an associated file at once using the manager. If a layer has
|
79
|
+
no associated `file_name`, it won't be altered.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
layer1 = SuperStack::Layer.new.load 'a_file_somewhere'
|
83
|
+
layer1 = SuperStack::Layer.new.load 'another_file_somewhere'
|
84
|
+
manager = SuperStack::Manager.new
|
85
|
+
|
86
|
+
manager << layer1
|
87
|
+
manager << layer2
|
88
|
+
|
89
|
+
manager.reload_layers
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
### Merge policies
|
94
|
+
|
95
|
+
You can get the list of merge policies by doing `SuperStack::MergePolicies.list`, but basically, four types currently
|
96
|
+
exist:
|
97
|
+
|
98
|
+
* `SuperStack::MergePolicies::KeepPolicy`, that when merging two layers will keep the first one (the one you are merging
|
99
|
+
to).
|
100
|
+
* `SuperStack::MergePolicies::OverridePolicy`, that when merging two layers will keep the second one(the one you are
|
101
|
+
merging with).
|
102
|
+
* `SuperStack::MergePolicies::StandardMergePolicy`, that will perform the ruby standard `Hash#merge` method. There are
|
103
|
+
a lot of limitations with it (like not recursive, not merging arrays within hash etc... read ruby doc for more).
|
104
|
+
**This is the default merge method**
|
105
|
+
* `SuperStack::MergePolicies::FullMergePolicy` is actually using the [deep_merge gem][DMG] to merge two hashes. It is
|
106
|
+
fully merging two hashes including arrays etc... Only when two types are incompatible (like Array replacing a String),
|
107
|
+
the second one replaces the first. Much more complete implementation than the one in ActiveSupport. The way it is used
|
108
|
+
in the gem is compliant with both the plain Ruby and the Rails implementations (see [the documentation][DMGithub])
|
109
|
+
|
110
|
+
The manager has a `default_merge_policy`, but each layer can have its own `merge_policy`. By default the internal merge
|
111
|
+
process will use the `default_merge_policy` except if a layer specifies its own.
|
112
|
+
|
113
|
+
In most cases you will just have to set the merge policy at the manager level using `default_merge_policy=`.
|
25
114
|
|
26
115
|
## Contributing
|
27
116
|
|
@@ -30,3 +119,8 @@ TODO: Write usage instructions here
|
|
30
119
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
120
|
4. Push to the branch (`git push origin my-new-feature`)
|
32
121
|
5. Create new Pull Request
|
122
|
+
|
123
|
+
|
124
|
+
[DMG]: https://rubygems.org/gems/deep_merge "Deep Merge gem"
|
125
|
+
[DMGithub]: https://github.com/danielsdeleo/deep_merge "Deep Merge Github project"
|
126
|
+
|
@@ -4,6 +4,7 @@ module SuperStack
|
|
4
4
|
module LayerWrapper
|
5
5
|
|
6
6
|
include Comparable
|
7
|
+
include SuperStack::MergePolicies::PolicyHandler
|
7
8
|
|
8
9
|
DEFAULT_LAYER_NAME = 'Unknown layer'
|
9
10
|
|
@@ -22,9 +23,14 @@ module SuperStack
|
|
22
23
|
@name || DEFAULT_LAYER_NAME
|
23
24
|
end
|
24
25
|
|
25
|
-
def load(file_name, type = :yaml)
|
26
|
-
raise
|
26
|
+
def load(file_name=self.file_name, type = :yaml)
|
27
|
+
raise "Cannot read file '#{file_name}'" unless File.readable? file_name
|
27
28
|
load_from_yaml file_name if type == :yaml
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def reload
|
33
|
+
self.load if has_file?
|
28
34
|
end
|
29
35
|
|
30
36
|
def has_file?
|
@@ -37,7 +43,17 @@ module SuperStack
|
|
37
43
|
end
|
38
44
|
|
39
45
|
def inspect
|
40
|
-
"
|
46
|
+
file_add_on = has_file? ? "file: '#{file_name}', " : ''
|
47
|
+
priority_add_on = priority.nil? ? '' : "priority: #{priority}, "
|
48
|
+
"{name: '#{name}', #{priority_add_on}#{file_add_on}#{super}}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_s
|
52
|
+
inspect
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.from_hash(hash)
|
56
|
+
hash.extend self
|
41
57
|
end
|
42
58
|
|
43
59
|
private
|
@@ -46,8 +62,9 @@ module SuperStack
|
|
46
62
|
begin
|
47
63
|
self.replace Hash[YAML::load(File.open(file_name)).map { |k, v| [k.to_sym, v] }]
|
48
64
|
|
49
|
-
rescue NoMethodError
|
65
|
+
rescue NoMethodError => e
|
50
66
|
# Empty file...
|
67
|
+
raise "Invalid file '#{file_name}'" unless e.message =~ /false:FalseClass/
|
51
68
|
end
|
52
69
|
@file_name = file_name
|
53
70
|
end
|
data/lib/super_stack/manager.rb
CHANGED
@@ -1,18 +1,28 @@
|
|
1
1
|
module SuperStack
|
2
2
|
class Manager
|
3
3
|
|
4
|
-
|
4
|
+
include SuperStack::MergePolicies::PolicyHandler
|
5
|
+
alias_method :default_merge_policy, :merge_policy
|
6
|
+
alias_method :'default_merge_policy=', :'merge_policy='
|
5
7
|
|
6
|
-
|
8
|
+
DEFAULT_PRIORITY_INTERVAL = 10
|
9
|
+
DEFAULT_MERGE_POLICY = SuperStack::MergePolicies::StandardMergePolicy
|
10
|
+
|
11
|
+
attr_reader :layers
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@layers = {}
|
15
|
+
self.default_merge_policy = DEFAULT_MERGE_POLICY
|
16
|
+
end
|
7
17
|
|
8
18
|
def [](filter=nil)
|
9
|
-
raise 'Manager not ready (no merge policy specified)' unless ready?
|
10
19
|
layers = to_a
|
11
20
|
return [] if layers.empty?
|
12
21
|
return layers[0] if layers.count == 1
|
13
22
|
first_layer = layers.shift
|
14
23
|
res = layers.inject(first_layer) do |stack, layer|
|
15
|
-
merge_policy.
|
24
|
+
policy_to_apply = layer.merge_policy.nil? ? default_merge_policy : layer.merge_policy
|
25
|
+
policy_to_apply.merge stack, layer
|
16
26
|
end
|
17
27
|
if filter.nil?
|
18
28
|
res
|
@@ -21,36 +31,45 @@ module SuperStack
|
|
21
31
|
end
|
22
32
|
end
|
23
33
|
|
24
|
-
def initialize
|
25
|
-
@layers = {}
|
26
|
-
end
|
27
|
-
|
28
34
|
def to_a
|
29
35
|
layers.values.sort
|
30
36
|
end
|
31
37
|
|
32
38
|
def add_layer(layer)
|
33
|
-
|
34
|
-
|
39
|
+
if layer.is_a? Hash and not layer.class.included_modules.include? SuperStack::LayerWrapper
|
40
|
+
SuperStack::LayerWrapper.from_hash layer
|
41
|
+
end
|
42
|
+
set_valid_name_for layer if layers.keys.include? layer.name
|
35
43
|
layer.priority = get_unused_priority if layer.priority.nil?
|
36
44
|
layers[layer.name] = layer
|
37
45
|
end
|
38
46
|
|
39
|
-
def
|
40
|
-
|
41
|
-
@merge_policy = policy
|
47
|
+
def <<(layer)
|
48
|
+
add_layer layer
|
42
49
|
end
|
43
50
|
|
44
|
-
def
|
45
|
-
|
51
|
+
def reload_layers
|
52
|
+
layers.values.each &:reload
|
46
53
|
end
|
47
54
|
|
48
55
|
private
|
49
56
|
|
50
57
|
def get_unused_priority
|
51
58
|
ordered = self.to_a
|
52
|
-
return
|
53
|
-
ordered.last.priority +
|
59
|
+
return DEFAULT_PRIORITY_INTERVAL if ordered.empty?
|
60
|
+
ordered.last.priority + DEFAULT_PRIORITY_INTERVAL
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_valid_name_for(layer)
|
64
|
+
name_pattern = /^(?<layer_name>.+) #(?<number>\d+)\s*$/
|
65
|
+
while layers.keys.include? layer.name
|
66
|
+
layer.name = "#{layer.name} #1" unless layer.name =~ name_pattern
|
67
|
+
layer.name.match(name_pattern) do |md|
|
68
|
+
layer.name = "#{md[:layer_name]} ##{md[:number].to_i + 1}"
|
69
|
+
next
|
70
|
+
end
|
71
|
+
end
|
72
|
+
layer.name
|
54
73
|
end
|
55
74
|
|
56
75
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'super_stack/merge_policies/keep_policy'
|
1
2
|
require 'super_stack/merge_policies/override_policy'
|
2
3
|
require 'super_stack/merge_policies/standard_merge_policy'
|
3
4
|
require 'super_stack/merge_policies/full_merge_policy'
|
@@ -10,5 +11,16 @@ module SuperStack
|
|
10
11
|
constants.map(&:to_s).grep(/Policy$/).map{|policy_name| const_get policy_name}
|
11
12
|
end
|
12
13
|
|
14
|
+
module PolicyHandler
|
15
|
+
|
16
|
+
attr_reader :merge_policy
|
17
|
+
|
18
|
+
def merge_policy=(policy)
|
19
|
+
raise "Invalid merge policy #{policy}" unless SuperStack::MergePolicies.list.include? policy
|
20
|
+
@merge_policy = policy
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
13
25
|
end
|
14
26
|
end
|
data/lib/super_stack/version.rb
CHANGED
data/spec/layer_spec.rb
CHANGED
@@ -13,6 +13,11 @@ describe SuperStack::Layer do
|
|
13
13
|
expect(subject.name == subject.class.const_get('DEFAULT_LAYER_NAME')).to be_truthy
|
14
14
|
end
|
15
15
|
|
16
|
+
it 'could have its own merge policy' do
|
17
|
+
expect( subject.respond_to? :merge_policy).to be_truthy
|
18
|
+
expect( subject.respond_to? :'merge_policy=').to be_truthy
|
19
|
+
end
|
20
|
+
|
16
21
|
it 'should allow to change the name' do
|
17
22
|
subject.name = 'foo'
|
18
23
|
expect(subject.name == 'foo').to be_truthy
|
@@ -31,15 +36,11 @@ describe SuperStack::Layer do
|
|
31
36
|
end
|
32
37
|
|
33
38
|
it 'can be created from any Hash' do
|
34
|
-
expect {
|
39
|
+
expect {SuperStack::LayerWrapper.from_hash Hash.new}.not_to raise_error
|
35
40
|
end
|
36
41
|
|
37
42
|
context 'when loaded from a YAML file' do
|
38
43
|
|
39
|
-
def file_from_type(file_type)
|
40
|
-
File.expand_path("../../test/layer_content_type_#{file_type}.yml", __FILE__)
|
41
|
-
end
|
42
|
-
|
43
44
|
%w(empty standard containing_an_array well_formatted).each do |file_type|
|
44
45
|
it "should allow #{file_type} content type" do
|
45
46
|
expect {
|
@@ -49,6 +50,33 @@ describe SuperStack::Layer do
|
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
53
|
+
it 'should remain unchanged when trying to load an invalid file' do
|
54
|
+
subject[:foo] = :bar
|
55
|
+
expect {
|
56
|
+
subject.load file_from_type 'invalid'
|
57
|
+
}.to raise_error
|
58
|
+
|
59
|
+
expect(subject[:foo] == :bar).to be_truthy
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should override current values when loaded from a valid file' do
|
63
|
+
subject[:foo] = :bar
|
64
|
+
expect {
|
65
|
+
subject.load file_from_type 'well_formatted'
|
66
|
+
}.not_to raise_error
|
67
|
+
|
68
|
+
expect(subject[:foo] == :bar).to be_falsey
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'reload should have no effect when no load has already been done' do
|
72
|
+
expect( subject.reload).to be_nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should allow to reload when a load has already been done' do
|
76
|
+
expect {subject.load file_from_type 'well_formatted'}.not_to raise_error
|
77
|
+
expect {subject.reload}.not_to raise_error
|
78
|
+
end
|
79
|
+
|
52
80
|
|
53
81
|
end
|
54
82
|
|
data/spec/manager_spec.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
|
3
4
|
describe SuperStack::Manager do
|
4
5
|
subject {SuperStack::Manager.new}
|
5
6
|
|
7
|
+
(1..4).each do |layer_number|
|
8
|
+
let("layer#{layer_number}".to_sym) {
|
9
|
+
file_name = file_from_layer layer_number
|
10
|
+
layer = SuperStack::Layer.new
|
11
|
+
layer.load file_name
|
12
|
+
layer.name = "layer#{layer_number}"
|
13
|
+
layer
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
6
17
|
|
7
18
|
it 'should contain layers' do
|
8
19
|
expect( subject.respond_to? :layers).to be_truthy
|
@@ -19,54 +30,83 @@ describe SuperStack::Manager do
|
|
19
30
|
subject.add_layer l2
|
20
31
|
subject.add_layer l1
|
21
32
|
|
33
|
+
expect(subject.layers.count == 2).to be_truthy
|
34
|
+
|
22
35
|
expect(subject.to_a[0] == l1).to be_truthy
|
23
36
|
expect(subject.to_a[1] == l2).to be_truthy
|
24
37
|
end
|
25
38
|
|
26
|
-
it 'should have a policy' do
|
27
|
-
expect( subject.respond_to? :
|
39
|
+
it 'should have a default policy' do
|
40
|
+
expect( subject.respond_to? :default_merge_policy).to be_truthy
|
41
|
+
expect( subject.respond_to? :'default_merge_policy=').to be_truthy
|
28
42
|
end
|
29
43
|
|
30
|
-
it 'should
|
31
|
-
expect( subject.
|
32
|
-
subject.merge_policy = SuperStack::MergePolicies.list[0]
|
33
|
-
expect( subject.ready?).to be_truthy
|
44
|
+
it 'should have a default merge policy' do
|
45
|
+
expect( subject.default_merge_policy == SuperStack::Manager::DEFAULT_MERGE_POLICY).to be_truthy
|
34
46
|
end
|
35
47
|
|
36
48
|
it 'should not accept stupid policies' do
|
37
|
-
expect {subject.
|
49
|
+
expect {subject.default_merge_policy = :foo}.to raise_error
|
38
50
|
end
|
39
51
|
|
40
|
-
|
52
|
+
it 'should support pure hashes as layers' do
|
53
|
+
expect {subject.add_layer({}) }.not_to raise_error
|
54
|
+
expect {subject.add_layer({}) }.not_to raise_error
|
55
|
+
expect(subject.layers.keys.count == 2).to be_truthy
|
56
|
+
expect(subject.layers.keys[0] == SuperStack::Layer::DEFAULT_LAYER_NAME).to be_truthy
|
57
|
+
expect(subject.layers.keys[1] == "#{SuperStack::Layer::DEFAULT_LAYER_NAME} #2").to be_truthy
|
58
|
+
end
|
41
59
|
|
42
|
-
|
43
|
-
|
44
|
-
|
60
|
+
it 'should allow the same layer to be added multiple times, automatically changing names' do
|
61
|
+
expect {subject.add_layer(layer1) }.not_to raise_error
|
62
|
+
expect {subject.add_layer(layer1) }.not_to raise_error
|
63
|
+
expect {subject.add_layer(layer1) }.not_to raise_error
|
64
|
+
expect(subject.layers.keys.count == 3).to be_truthy
|
65
|
+
expect(subject.layers.keys[0] == 'layer1').to be_truthy
|
66
|
+
expect(subject.layers.keys[1] == 'layer1 #2').to be_truthy
|
67
|
+
expect(subject.layers.keys[2] == 'layer1 #3').to be_truthy
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should allow to reload all layers at once' do
|
71
|
+
subject.add_layer layer1
|
72
|
+
subject << {bar: :foo}
|
73
|
+
subject.add_layer layer3
|
74
|
+
subject.add_layer layer4
|
75
|
+
expect(subject[:foo] == :bar).to be_falsey
|
76
|
+
subject.layers['layer3'][:foo] = :bar
|
77
|
+
expect(subject[:foo] == :bar).to be_truthy
|
78
|
+
expect(subject[:bar] == :foo).to be_truthy
|
79
|
+
expect {subject.reload_layers}.not_to raise_error
|
80
|
+
expect(subject[:foo] == :bar).to be_falsey
|
81
|
+
expect(subject[:bar] == :foo).to be_truthy
|
82
|
+
end
|
45
83
|
|
46
|
-
(1..4).each do |layer_number|
|
47
|
-
let("layer#{layer_number}".to_sym) {
|
48
|
-
file_name = file_from_layer layer_number
|
49
|
-
layer = SuperStack::Layer.new
|
50
|
-
layer.load file_name
|
51
|
-
layer.name = "layer#{layer_number}"
|
52
|
-
layer
|
53
|
-
}
|
54
|
-
end
|
55
84
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
85
|
+
SuperStack::MergePolicies.list.each do |policy|
|
86
|
+
it "should provide a merged view of the layers according to the merge policy: #{policy}" do
|
87
|
+
subject.add_layer layer1
|
88
|
+
subject.add_layer layer2
|
89
|
+
subject.add_layer layer3
|
90
|
+
subject.add_layer layer4
|
91
|
+
subject.default_merge_policy = policy
|
92
|
+
expect(subject[].is_a? Hash).to be_truthy
|
93
|
+
policy == SuperStack::MergePolicies::KeepPolicy ?
|
94
|
+
expect(subject[:layer] == 'one').to(be_truthy) : expect(subject[:layer] == 'four').to(be_truthy)
|
66
95
|
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when using policies at layer level' do
|
67
99
|
|
100
|
+
it 'should override the default manager policy' do
|
101
|
+
subject.add_layer layer1
|
102
|
+
subject.add_layer layer2
|
103
|
+
subject.default_merge_policy = SuperStack::MergePolicies::FullMergePolicy
|
104
|
+
layer2.merge_policy = SuperStack::MergePolicies::OverridePolicy
|
68
105
|
|
106
|
+
expect(subject[:from_layer_1]).to be_nil
|
107
|
+
expect(subject[:from_layer_2]).not_to be_nil
|
69
108
|
|
109
|
+
end
|
70
110
|
|
71
111
|
end
|
72
112
|
|
data/spec/merge_policies_spec.rb
CHANGED
@@ -4,10 +4,6 @@ describe SuperStack::MergePolicies do
|
|
4
4
|
|
5
5
|
subject {SuperStack::MergePolicies}
|
6
6
|
|
7
|
-
def file_from_layer(layer_number)
|
8
|
-
File.expand_path("../../test/stacked_layer_#{layer_number}.yml", __FILE__)
|
9
|
-
end
|
10
|
-
|
11
7
|
(1..4).each do |layer_number|
|
12
8
|
let("layer#{layer_number}".to_sym) {
|
13
9
|
file_name = file_from_layer layer_number
|
@@ -19,7 +15,19 @@ describe SuperStack::MergePolicies do
|
|
19
15
|
it 'should have merge policies' do
|
20
16
|
policies = subject.list
|
21
17
|
expect( policies.is_a? Array).to be_truthy
|
22
|
-
expect( policies.count ==
|
18
|
+
expect( policies.count == 4).to be_truthy
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when dealing with keep policy' do
|
22
|
+
|
23
|
+
subject {SuperStack::MergePolicies::KeepPolicy}
|
24
|
+
|
25
|
+
it 'should retain only the first hash' do
|
26
|
+
merged_hashs = subject.merge(layer1, layer2)
|
27
|
+
expect( merged_hashs == layer1).to be_truthy
|
28
|
+
expect( merged_hashs[:layer] == 'one').to be_truthy
|
29
|
+
end
|
30
|
+
|
23
31
|
end
|
24
32
|
|
25
33
|
context 'when dealing with override policy' do
|
data/spec/spec_helper.rb
CHANGED
@@ -17,6 +17,15 @@
|
|
17
17
|
|
18
18
|
require 'super_stack'
|
19
19
|
|
20
|
+
|
21
|
+
def file_from_layer(layer_number)
|
22
|
+
File.expand_path("../../test/stacked_layer_#{layer_number}.yml", __FILE__)
|
23
|
+
end
|
24
|
+
|
25
|
+
def file_from_type(file_type)
|
26
|
+
File.expand_path("../../test/layer_content_type_#{file_type}.yml", __FILE__)
|
27
|
+
end
|
28
|
+
|
20
29
|
RSpec.configure do |config|
|
21
30
|
# rspec-expectations config goes here. You can use an alternate
|
22
31
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore
|
2
|
+
magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis
|
3
|
+
nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie
|
4
|
+
consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit
|
5
|
+
praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
|
6
|
+
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem
|
7
|
+
insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius
|
8
|
+
quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum
|
9
|
+
est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula
|
10
|
+
quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_stack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurent B.
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/super_stack/manager.rb
|
102
102
|
- lib/super_stack/merge_policies.rb
|
103
103
|
- lib/super_stack/merge_policies/full_merge_policy.rb
|
104
|
+
- lib/super_stack/merge_policies/keep_policy.rb
|
104
105
|
- lib/super_stack/merge_policies/override_policy.rb
|
105
106
|
- lib/super_stack/merge_policies/standard_merge_policy.rb
|
106
107
|
- lib/super_stack/version.rb
|
@@ -111,6 +112,7 @@ files:
|
|
111
112
|
- super_stack.gemspec
|
112
113
|
- test/layer_content_type_containing_an_array.yml
|
113
114
|
- test/layer_content_type_empty.yml
|
115
|
+
- test/layer_content_type_invalid.yml
|
114
116
|
- test/layer_content_type_standard.yml
|
115
117
|
- test/layer_content_type_well_formatted.yml
|
116
118
|
- test/stacked_layer_1.yml
|
@@ -149,6 +151,7 @@ test_files:
|
|
149
151
|
- spec/spec_helper.rb
|
150
152
|
- test/layer_content_type_containing_an_array.yml
|
151
153
|
- test/layer_content_type_empty.yml
|
154
|
+
- test/layer_content_type_invalid.yml
|
152
155
|
- test/layer_content_type_standard.yml
|
153
156
|
- test/layer_content_type_well_formatted.yml
|
154
157
|
- test/stacked_layer_1.yml
|