ridley 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +48 -0
- data/lib/ridley.rb +1 -0
- data/lib/ridley/resources/environment.rb +48 -2
- data/lib/ridley/resources/node.rb +78 -4
- data/lib/ridley/version.rb +1 -1
- data/ridley.gemspec +1 -0
- data/spec/unit/ridley/resources/environment_spec.rb +88 -0
- data/spec/unit/ridley/resources/node_spec.rb +142 -0
- metadata +19 -3
data/README.md
CHANGED
@@ -274,6 +274,54 @@ Unlike a role, node, client, or environment, a data bag is a container for other
|
|
274
274
|
conn.search(:node)
|
275
275
|
conn.search(:node, "name:ridley-test.local")
|
276
276
|
|
277
|
+
## Manipulating Attributes
|
278
|
+
|
279
|
+
Using Ridley you can quickly manipulate node or environment attributes. Attributes are identified by a dotted path notation.
|
280
|
+
|
281
|
+
default[:my_app][:billing][:enabled] => "my_app.billing.enabled"
|
282
|
+
|
283
|
+
Given the previous example you could set the default node attribute with the `set_default_attribute` function on a Node object
|
284
|
+
|
285
|
+
### Node Attributes
|
286
|
+
|
287
|
+
Setting the `default[:my_app][:billing][:enabled]` node level default attribute on the node "jwinsor-1"
|
288
|
+
|
289
|
+
conn = Ridley.connection
|
290
|
+
conn.sync do
|
291
|
+
obj = node.find("jwinsor-1")
|
292
|
+
obj.set_default_attribute("my_app.billing.enabled", false)
|
293
|
+
obj.save
|
294
|
+
end
|
295
|
+
|
296
|
+
Other attribute precedence levels can be set with their own respective set attribute functions
|
297
|
+
|
298
|
+
conn = Ridley.connection
|
299
|
+
conn.sync do
|
300
|
+
obj = node.find("jwinsor-1")
|
301
|
+
obj.set_override_attribute("my_app.proxy.enabled", false)
|
302
|
+
obj.set_normal_attribute("my_app.webapp.enabled", false)
|
303
|
+
end
|
304
|
+
|
305
|
+
### Environment Attributes
|
306
|
+
|
307
|
+
Setting a default environment attribute is just like setting a node level default attribute
|
308
|
+
|
309
|
+
conn = Ridley.connection
|
310
|
+
conn.sync do
|
311
|
+
obj = environment.find("production")
|
312
|
+
obj.set_default_attribute("my_app.proxy.enabled", false)
|
313
|
+
obj.save
|
314
|
+
end
|
315
|
+
|
316
|
+
And the same goes for setting an environment level override attribute
|
317
|
+
|
318
|
+
conn = Ridley.connection
|
319
|
+
conn.sync do
|
320
|
+
obj = environment.find("production")
|
321
|
+
obj.set_override_attribute("my_app.webapp.enabled", false)
|
322
|
+
obj.save
|
323
|
+
end
|
324
|
+
|
277
325
|
# Authors and Contributors
|
278
326
|
|
279
327
|
* Jamie Winsor (<jamie@vialstudios.com>)
|
data/lib/ridley.rb
CHANGED
@@ -25,9 +25,55 @@ module Ridley
|
|
25
25
|
validates_presence_of :name
|
26
26
|
|
27
27
|
attribute :description, default: String.new
|
28
|
-
attribute :default_attributes, default:
|
29
|
-
attribute :override_attributes, default:
|
28
|
+
attribute :default_attributes, default: HashWithIndifferentAccess.new
|
29
|
+
attribute :override_attributes, default: HashWithIndifferentAccess.new
|
30
30
|
attribute :cookbook_versions, default: Hash.new
|
31
|
+
|
32
|
+
# @param [Hash] hash
|
33
|
+
def default_attributes=(hash)
|
34
|
+
super(HashWithIndifferentAccess.new(hash))
|
35
|
+
end
|
36
|
+
|
37
|
+
# @param [Hash] hash
|
38
|
+
def override_attributes=(hash)
|
39
|
+
super(HashWithIndifferentAccess.new(hash))
|
40
|
+
end
|
41
|
+
|
42
|
+
# Set an environment level default attribute given the dotted path representation of
|
43
|
+
# the Chef attribute and value
|
44
|
+
#
|
45
|
+
# @example setting and saving an environment level default attribute
|
46
|
+
#
|
47
|
+
# obj = environment.find("production")
|
48
|
+
# obj.set_defualt_attribute("my_app.billing.enabled", false)
|
49
|
+
# obj.save
|
50
|
+
#
|
51
|
+
# @param [String] key
|
52
|
+
# @param [Object] value
|
53
|
+
#
|
54
|
+
# @return [HashWithIndifferentAccess]
|
55
|
+
def set_default_attribute(key, value)
|
56
|
+
attr_hash = HashWithIndifferentAccess.from_dotted_path(key, value)
|
57
|
+
self.default_attributes = self.default_attributes.merge(attr_hash)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Set an environment level override attribute given the dotted path representation of
|
61
|
+
# the Chef attribute and value
|
62
|
+
#
|
63
|
+
# @example setting and saving an environment level override attribute
|
64
|
+
#
|
65
|
+
# obj = environment.find("production")
|
66
|
+
# obj.set_override_attribute("my_app.billing.enabled", false)
|
67
|
+
# obj.save
|
68
|
+
#
|
69
|
+
# @param [String] key
|
70
|
+
# @param [Object] value
|
71
|
+
#
|
72
|
+
# @return [HashWithIndifferentAccess]
|
73
|
+
def set_override_attribute(key, value)
|
74
|
+
attr_hash = HashWithIndifferentAccess.from_dotted_path(key, value)
|
75
|
+
self.override_attributes = self.override_attributes.merge(attr_hash)
|
76
|
+
end
|
31
77
|
end
|
32
78
|
|
33
79
|
module DSL
|
@@ -12,11 +12,85 @@ module Ridley
|
|
12
12
|
validates_presence_of :name
|
13
13
|
|
14
14
|
attribute :chef_environment, default: "_default"
|
15
|
-
attribute :automatic, default:
|
16
|
-
attribute :normal, default:
|
17
|
-
attribute :default, default:
|
18
|
-
attribute :override, default:
|
15
|
+
attribute :automatic, default: HashWithIndifferentAccess.new
|
16
|
+
attribute :normal, default: HashWithIndifferentAccess.new
|
17
|
+
attribute :default, default: HashWithIndifferentAccess.new
|
18
|
+
attribute :override, default: HashWithIndifferentAccess.new
|
19
19
|
attribute :run_list, default: Array.new
|
20
|
+
|
21
|
+
# @param [Hash] hash
|
22
|
+
def automatic=(hash)
|
23
|
+
super(HashWithIndifferentAccess.new(hash))
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param [Hash] hash
|
27
|
+
def normal=(hash)
|
28
|
+
super(HashWithIndifferentAccess.new(hash))
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param [Hash] hash
|
32
|
+
def default=(hash)
|
33
|
+
super(HashWithIndifferentAccess.new(hash))
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param [Hash] hash
|
37
|
+
def override=(hash)
|
38
|
+
super(HashWithIndifferentAccess.new(hash))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Set a node level override attribute given the dotted path representation of the Chef
|
42
|
+
# attribute and value
|
43
|
+
#
|
44
|
+
# @example setting and saving a node level override attribute
|
45
|
+
#
|
46
|
+
# obj = node.find("jwinsor-1")
|
47
|
+
# obj.set_override_attribute("my_app.billing.enabled", false)
|
48
|
+
# obj.save
|
49
|
+
#
|
50
|
+
# @param [String] key
|
51
|
+
# @param [Object] value
|
52
|
+
#
|
53
|
+
# @return [HashWithIndifferentAccess]
|
54
|
+
def set_override_attribute(key, value)
|
55
|
+
attr_hash = HashWithIndifferentAccess.from_dotted_path(key, value)
|
56
|
+
self.override = self.override.merge(attr_hash)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Set a node level default attribute given the dotted path representation of the Chef
|
60
|
+
# attribute and value
|
61
|
+
#
|
62
|
+
# @example setting and saving a node level default attribute
|
63
|
+
#
|
64
|
+
# obj = node.find("jwinsor-1")
|
65
|
+
# obj.set_default_attribute("my_app.billing.enabled", false)
|
66
|
+
# obj.save
|
67
|
+
#
|
68
|
+
# @param [String] key
|
69
|
+
# @param [Object] value
|
70
|
+
#
|
71
|
+
# @return [HashWithIndifferentAccess]
|
72
|
+
def set_default_attribute(key, value)
|
73
|
+
attr_hash = HashWithIndifferentAccess.from_dotted_path(key, value)
|
74
|
+
self.default = self.default.merge(attr_hash)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Set a node level normal attribute given the dotted path representation of the Chef
|
78
|
+
# attribute and value
|
79
|
+
#
|
80
|
+
# @example setting and saving a node level normal attribute
|
81
|
+
#
|
82
|
+
# obj = node.find("jwinsor-1")
|
83
|
+
# obj.set_normal_attribute("my_app.billing.enabled", false)
|
84
|
+
# obj.save
|
85
|
+
#
|
86
|
+
# @param [String] key
|
87
|
+
# @param [Object] value
|
88
|
+
#
|
89
|
+
# @return [HashWithIndifferentAccess]
|
90
|
+
def set_normal_attribute(key, value)
|
91
|
+
attr_hash = HashWithIndifferentAccess.from_dotted_path(key, value)
|
92
|
+
self.normal = self.normal.merge(attr_hash)
|
93
|
+
end
|
20
94
|
end
|
21
95
|
|
22
96
|
module DSL
|
data/lib/ridley/version.rb
CHANGED
data/ridley.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.version = Ridley::VERSION
|
17
17
|
s.required_ruby_version = ">= 1.9.1"
|
18
18
|
|
19
|
+
s.add_runtime_dependency 'chozo', '>= 0.0.2'
|
19
20
|
s.add_runtime_dependency 'yajl-ruby'
|
20
21
|
s.add_runtime_dependency 'mixlib-log'
|
21
22
|
s.add_runtime_dependency 'mixlib-authentication'
|
@@ -70,4 +70,92 @@ describe Ridley::Environment do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
let(:connection) { double('connection') }
|
75
|
+
|
76
|
+
subject { Ridley::Environment.new(connection) }
|
77
|
+
|
78
|
+
describe "#default_attributes=" do
|
79
|
+
context "given a Hash" do
|
80
|
+
it "returns a HashWithIndifferentAccess" do
|
81
|
+
subject.default_attributes = {
|
82
|
+
"key" => "value"
|
83
|
+
}
|
84
|
+
|
85
|
+
subject.default_attributes.should be_a(HashWithIndifferentAccess)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#override_attributes=" do
|
91
|
+
context "given a Hash" do
|
92
|
+
it "returns a HashWithIndifferentAccess" do
|
93
|
+
subject.override_attributes = {
|
94
|
+
"key" => "value"
|
95
|
+
}
|
96
|
+
|
97
|
+
subject.override_attributes.should be_a(HashWithIndifferentAccess)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#set_override_attribute" do
|
103
|
+
it "returns a HashWithIndifferentAccess" do
|
104
|
+
subject.set_override_attribute('deep.nested.item', true).should be_a(HashWithIndifferentAccess)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "sets an override node attribute at the nested path" do
|
108
|
+
subject.set_override_attribute('deep.nested.item', true)
|
109
|
+
|
110
|
+
subject.override_attributes.should have_key("deep")
|
111
|
+
subject.override_attributes["deep"].should have_key("nested")
|
112
|
+
subject.override_attributes["deep"]["nested"].should have_key("item")
|
113
|
+
subject.override_attributes["deep"]["nested"]["item"].should be_true
|
114
|
+
end
|
115
|
+
|
116
|
+
context "when the override attribute is already set" do
|
117
|
+
it "test" do
|
118
|
+
subject.override_attributes = {
|
119
|
+
deep: {
|
120
|
+
nested: {
|
121
|
+
item: false
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
subject.set_override_attribute('deep.nested.item', true)
|
126
|
+
|
127
|
+
subject.override_attributes["deep"]["nested"]["item"].should be_true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#set_default_attribute" do
|
133
|
+
it "returns a HashWithIndifferentAccess" do
|
134
|
+
subject.set_default_attribute('deep.nested.item', true).should be_a(HashWithIndifferentAccess)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "sets an override node attribute at the nested path" do
|
138
|
+
subject.set_default_attribute('deep.nested.item', true)
|
139
|
+
|
140
|
+
subject.default_attributes.should have_key("deep")
|
141
|
+
subject.default_attributes["deep"].should have_key("nested")
|
142
|
+
subject.default_attributes["deep"]["nested"].should have_key("item")
|
143
|
+
subject.default_attributes["deep"]["nested"]["item"].should be_true
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when the override attribute is already set" do
|
147
|
+
it "test" do
|
148
|
+
subject.default_attributes = {
|
149
|
+
deep: {
|
150
|
+
nested: {
|
151
|
+
item: false
|
152
|
+
}
|
153
|
+
}
|
154
|
+
}
|
155
|
+
subject.set_default_attribute('deep.nested.item', true)
|
156
|
+
|
157
|
+
subject.default_attributes["deep"]["nested"]["item"].should be_true
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
73
161
|
end
|
@@ -2,4 +2,146 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Ridley::Node do
|
4
4
|
it_behaves_like "a Ridley Resource", Ridley::Node
|
5
|
+
|
6
|
+
let(:connection) { double("connection") }
|
7
|
+
|
8
|
+
subject { Ridley::Node.new(connection) }
|
9
|
+
|
10
|
+
describe "#override=" do
|
11
|
+
context "given a Hash" do
|
12
|
+
it "returns a HashWithIndifferentAccess" do
|
13
|
+
subject.override = {
|
14
|
+
"key" => "value"
|
15
|
+
}
|
16
|
+
|
17
|
+
subject.override.should be_a(HashWithIndifferentAccess)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#automatic=" do
|
23
|
+
context "given a Hash" do
|
24
|
+
it "returns a HashWithIndifferentAccess" do
|
25
|
+
subject.automatic = {
|
26
|
+
"key" => "value"
|
27
|
+
}
|
28
|
+
|
29
|
+
subject.automatic.should be_a(HashWithIndifferentAccess)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#normal=" do
|
35
|
+
context "given a Hash" do
|
36
|
+
it "returns a HashWithIndifferentAccess" do
|
37
|
+
subject.normal = {
|
38
|
+
"key" => "value"
|
39
|
+
}
|
40
|
+
|
41
|
+
subject.normal.should be_a(HashWithIndifferentAccess)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#default=" do
|
47
|
+
context "given a Hash" do
|
48
|
+
it "returns a HashWithIndifferentAccess" do
|
49
|
+
subject.default = {
|
50
|
+
"key" => "value"
|
51
|
+
}
|
52
|
+
|
53
|
+
subject.default.should be_a(HashWithIndifferentAccess)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#set_override_attribute" do
|
59
|
+
it "returns a HashWithIndifferentAccess" do
|
60
|
+
subject.set_override_attribute('deep.nested.item', true).should be_a(HashWithIndifferentAccess)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "sets an override node attribute at the nested path" do
|
64
|
+
subject.set_override_attribute('deep.nested.item', true)
|
65
|
+
|
66
|
+
subject.override.should have_key("deep")
|
67
|
+
subject.override["deep"].should have_key("nested")
|
68
|
+
subject.override["deep"]["nested"].should have_key("item")
|
69
|
+
subject.override["deep"]["nested"]["item"].should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when the override attribute is already set" do
|
73
|
+
it "test" do
|
74
|
+
subject.override = {
|
75
|
+
deep: {
|
76
|
+
nested: {
|
77
|
+
item: false
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
subject.set_override_attribute('deep.nested.item', true)
|
82
|
+
|
83
|
+
subject.override["deep"]["nested"]["item"].should be_true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#set_normal_attribute" do
|
89
|
+
it "returns a HashWithIndifferentAccess" do
|
90
|
+
subject.set_normal_attribute('deep.nested.item', true).should be_a(HashWithIndifferentAccess)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "sets an normal node attribute at the nested path" do
|
94
|
+
subject.set_normal_attribute('deep.nested.item', true)
|
95
|
+
|
96
|
+
subject.normal.should have_key("deep")
|
97
|
+
subject.normal["deep"].should have_key("nested")
|
98
|
+
subject.normal["deep"]["nested"].should have_key("item")
|
99
|
+
subject.normal["deep"]["nested"]["item"].should be_true
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when the normal attribute is already set" do
|
103
|
+
it "test" do
|
104
|
+
subject.normal = {
|
105
|
+
deep: {
|
106
|
+
nested: {
|
107
|
+
item: false
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
subject.set_normal_attribute('deep.nested.item', true)
|
112
|
+
|
113
|
+
subject.normal["deep"]["nested"]["item"].should be_true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#set_default_attribute" do
|
119
|
+
it "returns a HashWithIndifferentAccess" do
|
120
|
+
subject.set_default_attribute('deep.nested.item', true).should be_a(HashWithIndifferentAccess)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "sets an default node attribute at the nested path" do
|
124
|
+
subject.set_default_attribute('deep.nested.item', true)
|
125
|
+
|
126
|
+
subject.default.should have_key("deep")
|
127
|
+
subject.default["deep"].should have_key("nested")
|
128
|
+
subject.default["deep"]["nested"].should have_key("item")
|
129
|
+
subject.default["deep"]["nested"]["item"].should be_true
|
130
|
+
end
|
131
|
+
|
132
|
+
context "when the default attribute is already set" do
|
133
|
+
it "test" do
|
134
|
+
subject.default = {
|
135
|
+
deep: {
|
136
|
+
nested: {
|
137
|
+
item: false
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
subject.set_default_attribute('deep.nested.item', true)
|
142
|
+
|
143
|
+
subject.default["deep"]["nested"]["item"].should be_true
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
5
147
|
end
|
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: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chozo
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.2
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: yajl-ruby
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -418,7 +434,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
418
434
|
version: '0'
|
419
435
|
segments:
|
420
436
|
- 0
|
421
|
-
hash:
|
437
|
+
hash: -3992965463787136581
|
422
438
|
requirements: []
|
423
439
|
rubyforge_project:
|
424
440
|
rubygems_version: 1.8.23
|