ridley 2.4.3 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/ridley/chef_objects/environment_object.rb +25 -15
- data/lib/ridley/chef_objects/node_object.rb +29 -0
- data/lib/ridley/version.rb +1 -1
- data/spec/unit/ridley/chef_objects/environment_object_spec.rb +43 -40
- data/spec/unit/ridley/chef_objects/node_object_spec.rb +38 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 364ab83ba70393de488496c740ddaea1cb57c005
|
4
|
+
data.tar.gz: c74c206b7a81f701e5ece67934416f30ecf27754
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 280a4d6de7745a0027dd883f27106a5b6f9d2f5aca5c5fb546dc482a0779d7c6d45f328cbb1c7f296db8ab5f9097f1a09720a4d9afd39d54ac48f4e47a42bb00
|
7
|
+
data.tar.gz: 98912ddbe6146749ebef916ba3b11f5b581af8e7bd32b8e518d64acabad946ee3afc7811c8ddbd0a6530ea86948ded06f44e324b32eed551cb7a0c49f9b2be15
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 2.4.4
|
2
|
+
|
3
|
+
* [#248](https://github.com/RiotGames/ridley/pull/248) Fix some edge cases and styling for deleting attributes from an environment
|
4
|
+
* [#247](https://github.com/RiotGames/ridley/pull/247) Add support for removing attributes from a node
|
5
|
+
|
1
6
|
# 2.4.3
|
2
7
|
|
3
8
|
* [#245](https://github.com/RiotGames/ridley/pull/245) Fix for numeric and boolean attribute types
|
@@ -62,9 +62,10 @@ module Ridley
|
|
62
62
|
# the dotted path to an attribute
|
63
63
|
#
|
64
64
|
# @return [Hashie::Mash]
|
65
|
-
def
|
66
|
-
|
65
|
+
def unset_default_attribute(key)
|
66
|
+
unset_attribute(key, :default)
|
67
67
|
end
|
68
|
+
alias :delete_default_attribute :unset_default_attribute
|
68
69
|
|
69
70
|
# Removes a environment override attribute given its dotted path
|
70
71
|
# representation. Returns the override attributes of the environment.
|
@@ -73,9 +74,10 @@ module Ridley
|
|
73
74
|
# the dotted path to an attribute
|
74
75
|
#
|
75
76
|
# @return [Hashie::Mash]
|
76
|
-
def
|
77
|
-
|
77
|
+
def unset_override_attribute(key)
|
78
|
+
unset_attribute(key, :override)
|
78
79
|
end
|
80
|
+
alias :delete_override_attribute :unset_override_attribute
|
79
81
|
|
80
82
|
private
|
81
83
|
|
@@ -87,18 +89,26 @@ module Ridley
|
|
87
89
|
# the precedence level to delete the attribute from
|
88
90
|
#
|
89
91
|
# @return [Hashie::Mash]
|
90
|
-
def
|
91
|
-
|
92
|
-
leaf_key =
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
92
|
+
def unset_attribute(key, precedence)
|
93
|
+
keys = key.split(".")
|
94
|
+
leaf_key = keys.pop
|
95
|
+
|
96
|
+
attributes_to_change = case precedence
|
97
|
+
when :default
|
98
|
+
self.default_attributes
|
99
|
+
when :override
|
100
|
+
self.override_attributes
|
101
|
+
end
|
102
|
+
|
103
|
+
leaf_attributes = keys.inject(attributes_to_change) do |attributes, key|
|
104
|
+
if attributes[key] && attributes[key].kind_of?(Hashie::Mash)
|
105
|
+
attributes = attributes[key]
|
106
|
+
else
|
107
|
+
return attributes_to_change
|
108
|
+
end
|
98
109
|
end
|
99
|
-
|
100
|
-
|
101
|
-
attributes_to_change
|
110
|
+
leaf_attributes.delete(leaf_key)
|
111
|
+
return attributes_to_change
|
102
112
|
end
|
103
113
|
end
|
104
114
|
end
|
@@ -51,6 +51,7 @@ module Ridley
|
|
51
51
|
# obj.save
|
52
52
|
#
|
53
53
|
# @param [String] key
|
54
|
+
# dotted path to key to be unset
|
54
55
|
# @param [Object] value
|
55
56
|
#
|
56
57
|
# @return [Hashie::Mash]
|
@@ -59,6 +60,34 @@ module Ridley
|
|
59
60
|
self.normal = self.normal.deep_merge(attr_hash)
|
60
61
|
end
|
61
62
|
|
63
|
+
# Unset a node level normal attribute given the dotted path representation of the Chef
|
64
|
+
# attribute and value.
|
65
|
+
#
|
66
|
+
# @example unsetting and saving a node level normal attribute
|
67
|
+
#
|
68
|
+
# obj = node.find("foonode")
|
69
|
+
# obj.unset_chef_attribute("my_app.service_one.service_state")
|
70
|
+
# obj.save
|
71
|
+
#
|
72
|
+
# @param [String] key
|
73
|
+
# dotted path to key to be unset
|
74
|
+
#
|
75
|
+
# @return [Hashie::Mash]
|
76
|
+
def unset_chef_attribute(key)
|
77
|
+
keys = key.split(".")
|
78
|
+
leaf_key = keys.pop
|
79
|
+
attributes = keys.inject(self.normal) do |attributes, key|
|
80
|
+
if attributes[key] && attributes[key].kind_of?(Hashie::Mash)
|
81
|
+
attributes = attributes[key]
|
82
|
+
else
|
83
|
+
return self.normal
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
attributes.delete(leaf_key)
|
88
|
+
return self.normal
|
89
|
+
end
|
90
|
+
|
62
91
|
# Returns the public hostname of the instantiated node. This hostname should be used for
|
63
92
|
# public communications to the node.
|
64
93
|
#
|
data/lib/ridley/version.rb
CHANGED
@@ -5,12 +5,12 @@ describe Ridley::EnvironmentObject do
|
|
5
5
|
|
6
6
|
describe "#set_override_attribute" do
|
7
7
|
it "sets an override node attribute at the nested path" do
|
8
|
-
|
8
|
+
subject.set_override_attribute('deep.nested.item', true)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
subject.override_attributes.should have_key("deep")
|
11
|
+
subject.override_attributes["deep"].should have_key("nested")
|
12
|
+
subject.override_attributes["deep"]["nested"].should have_key("item")
|
13
|
+
subject.override_attributes["deep"]["nested"]["item"].should be_true
|
14
14
|
end
|
15
15
|
|
16
16
|
context "when the override attribute is already set" do
|
@@ -31,12 +31,12 @@ describe Ridley::EnvironmentObject do
|
|
31
31
|
|
32
32
|
describe "#set_default_attribute" do
|
33
33
|
it "sets an override node attribute at the nested path" do
|
34
|
-
|
34
|
+
subject.set_default_attribute('deep.nested.item', true)
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
subject.default_attributes.should have_key("deep")
|
37
|
+
subject.default_attributes["deep"].should have_key("nested")
|
38
|
+
subject.default_attributes["deep"]["nested"].should have_key("item")
|
39
|
+
subject.default_attributes["deep"]["nested"]["item"].should be_true
|
40
40
|
end
|
41
41
|
|
42
42
|
context "when the override attribute is already set" do
|
@@ -54,62 +54,65 @@ describe Ridley::EnvironmentObject do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
let(:
|
59
|
-
let(:
|
57
|
+
shared_examples_for "attribute deleter" do
|
58
|
+
let(:precedence) { raise "You must provide the precedence level (let(:precedence) { \"default\" } in the shared example context" }
|
59
|
+
let(:delete_attribute) { subject.send(:"delete_#{precedence}_attribute", delete_attribute_key) }
|
60
|
+
let(:set_attribute_value) { true }
|
61
|
+
let(:attributes) { { "hello" => { "world" => set_attribute_value } } }
|
62
|
+
let(:delete_attribute_key) { "hello.world" }
|
60
63
|
|
61
64
|
before do
|
62
|
-
subject.
|
65
|
+
subject.send(:"#{precedence}_attributes=", attributes)
|
63
66
|
end
|
64
67
|
|
65
|
-
it "removes the
|
66
|
-
|
67
|
-
expect(subject.
|
68
|
+
it "removes the attribute" do
|
69
|
+
delete_attribute
|
70
|
+
expect(subject.send(:"#{precedence}_attributes")[:hello][:world]).to be_nil
|
68
71
|
end
|
69
72
|
|
70
73
|
context "when the attribute does not exist" do
|
71
|
-
let(:
|
74
|
+
let(:delete_attribute_key) { "not.existing" }
|
72
75
|
|
73
76
|
it "does not delete anything" do
|
74
|
-
|
75
|
-
expect(subject.
|
77
|
+
delete_attribute
|
78
|
+
expect(subject.send(:"#{precedence}_attributes")[:hello][:world]).to eq(set_attribute_value)
|
76
79
|
end
|
77
80
|
end
|
78
81
|
|
79
82
|
context "when an internal hash is nil" do
|
80
|
-
let(:
|
83
|
+
let(:delete_attribute_key) { "never.not.existing" }
|
81
84
|
|
82
85
|
before do
|
83
|
-
subject.
|
86
|
+
subject.send(:"#{precedence}_attributes=", Hash.new)
|
84
87
|
end
|
85
88
|
|
86
89
|
it "does not delete anything" do
|
87
|
-
|
88
|
-
expect(subject.
|
90
|
+
delete_attribute
|
91
|
+
expect(subject.send(:"#{precedence}_attributes")).to be_empty
|
89
92
|
end
|
90
93
|
end
|
91
|
-
end
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
-
|
95
|
+
["string", true, :symbol, ["array"], Object.new].each do |nonattrs|
|
96
|
+
context "when the attribute chain is partially set, interrupted by a #{nonattrs.class}" do
|
97
|
+
let(:attributes) { { "hello" => set_attribute_value } }
|
98
|
+
let(:set_attribute_value) { nonattrs }
|
96
99
|
|
97
|
-
|
98
|
-
|
100
|
+
it "leaves the attributes unchanged" do
|
101
|
+
expect(subject.send(:"unset_#{precedence}_attribute", delete_attribute_key).to_hash).to eq(attributes)
|
102
|
+
end
|
103
|
+
end
|
99
104
|
end
|
105
|
+
end
|
100
106
|
|
101
|
-
|
102
|
-
|
103
|
-
|
107
|
+
describe "#delete_default_attribute" do
|
108
|
+
it_behaves_like "attribute deleter" do
|
109
|
+
let(:precedence) { "default" }
|
104
110
|
end
|
111
|
+
end
|
105
112
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
it "does not delete anything" do
|
110
|
-
delete_override_attribute
|
111
|
-
expect(subject.override_attributes[:hello][:world]).to be_true
|
112
|
-
end
|
113
|
+
describe "#delete_override_attribute" do
|
114
|
+
it_behaves_like "attribute deleter" do
|
115
|
+
let(:precedence) { "override" }
|
113
116
|
end
|
114
117
|
end
|
115
118
|
end
|
@@ -55,7 +55,7 @@ describe Ridley::NodeObject do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
describe "#set_chef_attribute" do
|
58
|
-
it "sets
|
58
|
+
it "sets a normal node attribute at the nested path" do
|
59
59
|
subject.set_chef_attribute('deep.nested.item', true)
|
60
60
|
|
61
61
|
subject.normal.should have_key("deep")
|
@@ -80,6 +80,43 @@ describe Ridley::NodeObject do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
describe "#unset_chef_attribute" do
|
84
|
+
context "when the attribute is set" do
|
85
|
+
before do
|
86
|
+
subject.normal = { foo: { bar: { baz: true } } }
|
87
|
+
end
|
88
|
+
|
89
|
+
it "unsets a normal node attribute at the nested path" do
|
90
|
+
subject.unset_chef_attribute("foo.bar.baz")
|
91
|
+
expect(subject.normal[:foo][:bar][:baz]).to be_nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
["string", true, :symbol, ["array"], Object.new].each do |nonattrs|
|
96
|
+
context "when the attribute chain is partially set, interrupted by a #{nonattrs.class}" do
|
97
|
+
let(:attributes) { { 'foo' => { 'bar' => nonattrs } } }
|
98
|
+
before do
|
99
|
+
subject.normal = attributes
|
100
|
+
end
|
101
|
+
|
102
|
+
it "leaves the attributes unchanged" do
|
103
|
+
expect(subject.unset_chef_attribute("foo.bar.baz").to_hash).to eq(attributes)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when the attribute is not set" do
|
109
|
+
let(:attributes) { { 'bizz' => { 'bar' => { 'baz' => true } } } }
|
110
|
+
before do
|
111
|
+
subject.normal = attributes
|
112
|
+
end
|
113
|
+
|
114
|
+
it "leaves the attributes unchanged" do
|
115
|
+
expect(subject.unset_chef_attribute("foo.bar.baz").to_hash).to eq(attributes)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
83
120
|
describe "#cloud?" do
|
84
121
|
it "returns true if the cloud automatic attribute is set" do
|
85
122
|
subject.automatic = {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Winsor
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|