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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76add10f7d0cfee05331ae99481f011e868261db
4
- data.tar.gz: 571ef4c873bbb8ab9697d87f008b0f6dfea9fdbb
3
+ metadata.gz: 364ab83ba70393de488496c740ddaea1cb57c005
4
+ data.tar.gz: c74c206b7a81f701e5ece67934416f30ecf27754
5
5
  SHA512:
6
- metadata.gz: a9e15f5a280702aa0b60f05dfddf10da424c0ab4c0c885cc92fe8e29bb47ba0b115fa015e26f605012c4809fca15af79b4557be197e1c75269f3b350b7d24fc1
7
- data.tar.gz: 1b1daa08465102f140943cbc8f4209d15136f6c3006d25f4fb87b85e843ae0f9984cbd56476a19d4ed86bd3097a27261179512f50d390ee6516d2587ec5bdace
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 delete_default_attribute(key)
66
- delete_attribute(key, :default)
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 delete_override_attribute(key)
77
- delete_attribute(key, :override)
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 delete_attribute(key, precedence)
91
- dotted_path = key.split('.')
92
- leaf_key = dotted_path.pop
93
- case precedence
94
- when :default
95
- attributes_to_change = self.default_attributes
96
- when :override
97
- attributes_to_change = self.override_attributes
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
- leaf_hash = dotted_path.inject(attributes_to_change) { |hash, element| hash[element] unless hash == nil }
100
- leaf_hash.delete(leaf_key) unless leaf_hash.nil?
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
  #
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "2.4.3"
2
+ VERSION = "2.4.4"
3
3
  end
@@ -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
- subject.set_override_attribute('deep.nested.item', true)
8
+ subject.set_override_attribute('deep.nested.item', true)
9
9
 
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
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
- subject.set_default_attribute('deep.nested.item', true)
34
+ subject.set_default_attribute('deep.nested.item', true)
35
35
 
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
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
- describe "#delete_default_attribute" do
58
- let(:delete_default_attribute) { subject.delete_default_attribute(attribute_key) }
59
- let(:attribute_key) { "hello.world" }
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.set_default_attribute(attribute_key, true)
65
+ subject.send(:"#{precedence}_attributes=", attributes)
63
66
  end
64
67
 
65
- it "removes the default attribute" do
66
- delete_default_attribute
67
- expect(subject.default_attributes[:hello][:world]).to be_nil
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(:delete_default_attribute) { subject.delete_default_attribute("not.existing") }
74
+ let(:delete_attribute_key) { "not.existing" }
72
75
 
73
76
  it "does not delete anything" do
74
- delete_default_attribute
75
- expect(subject.default_attributes[:hello][:world]).to be_true
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(:delete_default_attribute) { subject.delete_default_attribute("never.not.existing") }
83
+ let(:delete_attribute_key) { "never.not.existing" }
81
84
 
82
85
  before do
83
- subject.default_attributes = Hash.new
86
+ subject.send(:"#{precedence}_attributes=", Hash.new)
84
87
  end
85
88
 
86
89
  it "does not delete anything" do
87
- delete_default_attribute
88
- expect(subject.default_attributes).to be_empty
90
+ delete_attribute
91
+ expect(subject.send(:"#{precedence}_attributes")).to be_empty
89
92
  end
90
93
  end
91
- end
92
94
 
93
- describe "#delete_override_attribute" do
94
- let(:delete_override_attribute) { subject.delete_override_attribute(attribute_key) }
95
- let(:attribute_key) { "hello.world" }
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
- before do
98
- subject.set_override_attribute(attribute_key, true)
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
- it "removes the override attribute" do
102
- delete_override_attribute
103
- expect(subject.override_attributes[:hello][:world]).to be_nil
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
- context "when the attribute does not exist" do
107
- let(:delete_override_attribute) { subject.delete_override_attribute("not.existing") }
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 an normal node attribute at the nested path" do
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.3
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-04 00:00:00.000000000 Z
12
+ date: 2014-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable