ridley 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/ridley/connection.rb
CHANGED
@@ -144,6 +144,14 @@ module Ridley
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def method_missing(method, *args, &block)
|
147
|
+
if block_given?
|
148
|
+
@self_before_instance_eval ||= eval("self", block.binding)
|
149
|
+
end
|
150
|
+
|
151
|
+
if @self_before_instance_eval.nil?
|
152
|
+
super
|
153
|
+
end
|
154
|
+
|
147
155
|
@self_before_instance_eval.send(method, *args, &block)
|
148
156
|
end
|
149
157
|
end
|
data/lib/ridley/resource.rb
CHANGED
@@ -245,6 +245,14 @@ module Ridley
|
|
245
245
|
true
|
246
246
|
end
|
247
247
|
|
248
|
+
# Reload the attributes of the instantiated resource
|
249
|
+
#
|
250
|
+
# @return [Object]
|
251
|
+
def reload
|
252
|
+
self.attributes = self.class.find(connection, self).attributes
|
253
|
+
self
|
254
|
+
end
|
255
|
+
|
248
256
|
# @return [String]
|
249
257
|
def chef_id
|
250
258
|
attribute(self.class.chef_id)
|
@@ -38,44 +38,16 @@ module Ridley
|
|
38
38
|
super(HashWithIndifferentAccess.new(hash))
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
42
|
-
|
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)
|
41
|
+
# @param [Hash] hash
|
42
|
+
def normal=(hash)
|
43
|
+
super(HashWithIndifferentAccess.new(hash))
|
75
44
|
end
|
76
45
|
|
77
46
|
# Set a node level normal attribute given the dotted path representation of the Chef
|
78
|
-
# attribute and value
|
47
|
+
# attribute and value.
|
48
|
+
#
|
49
|
+
# @note It is not possible to set any other attribute level on a node and have it persist after
|
50
|
+
# a Chef Run. This is because all other attribute levels are truncated at the start of a Chef Run.
|
79
51
|
#
|
80
52
|
# @example setting and saving a node level normal attribute
|
81
53
|
#
|
@@ -87,7 +59,7 @@ module Ridley
|
|
87
59
|
# @param [Object] value
|
88
60
|
#
|
89
61
|
# @return [HashWithIndifferentAccess]
|
90
|
-
def
|
62
|
+
def set_attribute(key, value)
|
91
63
|
attr_hash = HashWithIndifferentAccess.from_dotted_path(key, value)
|
92
64
|
self.normal = self.normal.merge(attr_hash)
|
93
65
|
end
|
data/lib/ridley/version.rb
CHANGED
@@ -234,4 +234,24 @@ shared_examples_for "a Ridley Resource" do |resource_klass|
|
|
234
234
|
@object.name.should eql("reset")
|
235
235
|
end
|
236
236
|
end
|
237
|
+
|
238
|
+
describe "#reload" do
|
239
|
+
let(:updated_subject) { double('updated_subject', attributes: { fake_attribute: "some_value" }) }
|
240
|
+
|
241
|
+
before(:each) do
|
242
|
+
subject.class.attribute(:fake_attribute)
|
243
|
+
subject.class.stub(:find).with(connection, subject).and_return(updated_subject)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "returns itself" do
|
247
|
+
subject.reload.should eql(subject)
|
248
|
+
end
|
249
|
+
|
250
|
+
it "sets the attributes of self to include those of the reloaded object" do
|
251
|
+
subject.reload
|
252
|
+
|
253
|
+
subject.attributes.should have_key(:fake_attribute)
|
254
|
+
subject.attributes[:fake_attribute].should eql("some_value")
|
255
|
+
end
|
256
|
+
end
|
237
257
|
end
|
@@ -55,43 +55,13 @@ describe Ridley::Node do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe "#
|
58
|
+
describe "#set_attribute" do
|
59
59
|
it "returns a HashWithIndifferentAccess" do
|
60
|
-
subject.
|
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)
|
60
|
+
subject.set_attribute('deep.nested.item', true).should be_a(HashWithIndifferentAccess)
|
91
61
|
end
|
92
62
|
|
93
63
|
it "sets an normal node attribute at the nested path" do
|
94
|
-
subject.
|
64
|
+
subject.set_attribute('deep.nested.item', true)
|
95
65
|
|
96
66
|
subject.normal.should have_key("deep")
|
97
67
|
subject.normal["deep"].should have_key("nested")
|
@@ -108,43 +78,13 @@ describe Ridley::Node do
|
|
108
78
|
}
|
109
79
|
}
|
110
80
|
}
|
111
|
-
subject.
|
81
|
+
subject.set_attribute('deep.nested.item', true)
|
112
82
|
|
113
83
|
subject.normal["deep"]["nested"]["item"].should be_true
|
114
84
|
end
|
115
85
|
end
|
116
86
|
end
|
117
87
|
|
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
|
147
|
-
|
148
88
|
describe "#eucalyptus?" do
|
149
89
|
it "returns true if the eucalyptus automatic attribute is set" do
|
150
90
|
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: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chozo
|
@@ -434,7 +434,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
434
434
|
version: '0'
|
435
435
|
segments:
|
436
436
|
- 0
|
437
|
-
hash:
|
437
|
+
hash: 3213701153565876278
|
438
438
|
requirements: []
|
439
439
|
rubyforge_project:
|
440
440
|
rubygems_version: 1.8.23
|