ridley 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,7 +24,7 @@ module Ridley
24
24
  #
25
25
  # @return [Hash]
26
26
  def parse(body)
27
- MultiJson.decode(body, symbolize_keys: true)
27
+ HashWithIndifferentAccess.new MultiJson.decode(body)
28
28
  end
29
29
 
30
30
  # Extracts the type of the response from the response headers
@@ -62,8 +62,7 @@ module Ridley
62
62
  #
63
63
  # @return [Boolean]
64
64
  def json_response?(env)
65
- response_type(env) == JSON_TYPE ||
66
- looks_like_json?(env)
65
+ response_type(env) == JSON_TYPE || looks_like_json?(env)
67
66
  end
68
67
 
69
68
  # Examines the body of a request env and returns true if it appears
@@ -68,7 +68,7 @@ module Ridley
68
68
 
69
69
  # @return [Hash]
70
70
  def attribute_defaults
71
- @attribute_defaults ||= Hash.new
71
+ @attribute_defaults ||= HashWithIndifferentAccess.new
72
72
  end
73
73
 
74
74
  # @param [String, Symbol] name
@@ -98,15 +98,20 @@ module Ridley
98
98
  end
99
99
  end
100
100
 
101
+ # @return [Ridley::DataBag]
101
102
  attr_reader :data_bag
103
+ # @return [HashWithIndifferentAccess]
104
+ attr_reader :attributes
102
105
 
103
- attr_accessor :attributes
104
106
  validates_presence_of :id
105
107
 
108
+ # @param [Ridley::Connection] connection
109
+ # @param [Ridley::DataBag] data_bag
110
+ # @param [#to_hash] attributes
106
111
  def initialize(connection, data_bag, attributes = {})
107
112
  @connection = connection
108
113
  @data_bag = data_bag
109
- @attributes = attributes
114
+ self.attributes = attributes
110
115
  end
111
116
 
112
117
  # Alias for accessing the value of the 'id' attribute
@@ -134,6 +139,13 @@ module Ridley
134
139
  end
135
140
  alias_method :[]=, :attribute=
136
141
 
142
+ # @param [#to_hash] new_attributes
143
+ #
144
+ # @return [HashWithIndifferentAccess]
145
+ def attributes=(new_attributes)
146
+ @attributes = HashWithIndifferentAccess.new(new_attributes.to_hash)
147
+ end
148
+
137
149
  # Creates a resource on the target remote or updates one if the resource
138
150
  # already exists.
139
151
  #
@@ -156,7 +168,7 @@ module Ridley
156
168
  #
157
169
  # @return [Object]
158
170
  def from_hash(hash)
159
- hash = hash.to_hash
171
+ hash = HashWithIndifferentAccess.new(hash.to_hash)
160
172
 
161
173
  self.attributes = hash.has_key?(:raw_data) ? hash[:raw_data] : hash
162
174
  self
@@ -181,6 +193,7 @@ module Ridley
181
193
 
182
194
  private
183
195
 
196
+ # @return [Ridley::Connection]
184
197
  attr_reader :connection
185
198
  end
186
199
  end
@@ -27,7 +27,7 @@ module Ridley
27
27
  attribute :description, default: String.new
28
28
  attribute :default_attributes, default: HashWithIndifferentAccess.new
29
29
  attribute :override_attributes, default: HashWithIndifferentAccess.new
30
- attribute :cookbook_versions, default: Hash.new
30
+ attribute :cookbook_versions, default: HashWithIndifferentAccess.new
31
31
 
32
32
  # @param [Hash] hash
33
33
  def default_attributes=(hash)
@@ -39,6 +39,10 @@ module Ridley
39
39
  super(HashWithIndifferentAccess.new(hash))
40
40
  end
41
41
 
42
+ def cookbook_versions=(hash)
43
+ super(HashWithIndifferentAccess.new(hash))
44
+ end
45
+
42
46
  # Set an environment level default attribute given the dotted path representation of
43
47
  # the Chef attribute and value
44
48
  #
@@ -91,6 +91,14 @@ module Ridley
91
91
  attr_hash = HashWithIndifferentAccess.from_dotted_path(key, value)
92
92
  self.normal = self.normal.merge(attr_hash)
93
93
  end
94
+
95
+ def eucalyptus?
96
+ self.automatic.has_key?(:eucalyptus)
97
+ end
98
+
99
+ def ec2?
100
+ self.automatic.has_key?(:ec2)
101
+ end
94
102
  end
95
103
 
96
104
  module DSL
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -16,7 +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
+ s.add_runtime_dependency 'chozo', '>= 0.0.3'
20
20
  s.add_runtime_dependency 'yajl-ruby'
21
21
  s.add_runtime_dependency 'mixlib-log'
22
22
  s.add_runtime_dependency 'mixlib-authentication'
@@ -69,7 +69,13 @@ describe "DataBag API operations", type: "acceptance" do
69
69
  describe "retrieving a data bag item" do
70
70
  it "returns the desired item in the data bag" do
71
71
  attributes = {
72
- id: "appconfig", host: "host.local", port: 80, admin: false, servers: ["one"]
72
+ "id" => "appconfig",
73
+ "host" => "host.local",
74
+ "port" => 80,
75
+ "admin" => false,
76
+ "servers" => [
77
+ "one"
78
+ ]
73
79
  }
74
80
  @databag.item.create(attributes)
75
81
 
@@ -80,8 +86,8 @@ describe "DataBag API operations", type: "acceptance" do
80
86
  describe "deleting a data bag item" do
81
87
  let(:attributes) do
82
88
  {
83
- id: "appconfig",
84
- host: "host.local"
89
+ "id" => "appconfig",
90
+ "host" => "host.local"
85
91
  }
86
92
  end
87
93
 
@@ -90,16 +96,16 @@ describe "DataBag API operations", type: "acceptance" do
90
96
  end
91
97
 
92
98
  it "returns the deleted data bag item" do
93
- dbi = @databag.item.delete(attributes[:id])
99
+ dbi = @databag.item.delete(attributes["id"])
94
100
 
95
101
  dbi.should be_a(Ridley::DataBagItem)
96
102
  dbi.attributes.should eql(attributes)
97
103
  end
98
104
 
99
105
  it "deletes the data bag item from the server" do
100
- @databag.item.delete(attributes[:id])
106
+ @databag.item.delete(attributes["id"])
101
107
 
102
- @databag.item.find(attributes[:id]).should be_nil
108
+ @databag.item.find(attributes["id"]).should be_nil
103
109
  end
104
110
  end
105
111
 
@@ -124,9 +124,9 @@ describe "Environment API operations", type: "acceptance" do
124
124
 
125
125
  it "saves a new set of 'default_attributes'" do
126
126
  target.default_attributes = default_attributes = {
127
- attribute_one: "val_one",
128
- nested: {
129
- other: "val"
127
+ "attribute_one" => "val_one",
128
+ "nested" => {
129
+ "other" => "val"
130
130
  }
131
131
  }
132
132
 
@@ -140,9 +140,9 @@ describe "Environment API operations", type: "acceptance" do
140
140
 
141
141
  it "saves a new set of 'override_attributes'" do
142
142
  target.override_attributes = override_attributes = {
143
- attribute_one: "val",
144
- nested: {
145
- other: "val"
143
+ "attribute_one" => "val_one",
144
+ "nested" => {
145
+ "other" => "val"
146
146
  }
147
147
  }
148
148
 
@@ -156,8 +156,8 @@ describe "Environment API operations", type: "acceptance" do
156
156
 
157
157
  it "saves a new set of 'cookbook_versions'" do
158
158
  target.cookbook_versions = cookbook_versions = {
159
- nginx: "1.2.0",
160
- tomcat: "1.3.0"
159
+ "nginx" => "1.2.0",
160
+ "tomcat" => "1.3.0"
161
161
  }
162
162
 
163
163
  connection.sync do
@@ -131,9 +131,9 @@ describe "Node API operations", type: "acceptance" do
131
131
 
132
132
  it "saves a new set of 'normal' attributes" do
133
133
  target.normal = normal = {
134
- attribute_one: "value_one",
135
- nested: {
136
- other: "val"
134
+ "attribute_one" => "value_one",
135
+ "nested" => {
136
+ "other" => "val"
137
137
  }
138
138
  }
139
139
 
@@ -147,9 +147,9 @@ describe "Node API operations", type: "acceptance" do
147
147
 
148
148
  it "saves a new set of 'default' attributes" do
149
149
  target.default = defaults = {
150
- attribute_one: "val_one",
151
- nested: {
152
- other: "val"
150
+ "attribute_one" => "val_one",
151
+ "nested" => {
152
+ "other" => "val"
153
153
  }
154
154
  }
155
155
 
@@ -163,9 +163,9 @@ describe "Node API operations", type: "acceptance" do
163
163
 
164
164
  it "saves a new set of 'automatic' attributes" do
165
165
  target.automatic = automatics = {
166
- attribute_one: "val_one",
167
- nested: {
168
- other: "val"
166
+ "attribute_one" => "val_one",
167
+ "nested" => {
168
+ "other" => "val"
169
169
  }
170
170
  }
171
171
 
@@ -179,9 +179,9 @@ describe "Node API operations", type: "acceptance" do
179
179
 
180
180
  it "saves a new set of 'override' attributes" do
181
181
  target.override = overrides = {
182
- attribute_one: "val_one",
183
- nested: {
184
- other: "val"
182
+ "attribute_one" => "val_one",
183
+ "nested" => {
184
+ "other" => "val"
185
185
  }
186
186
  }
187
187
 
@@ -142,8 +142,8 @@ describe "Role API operations", type: "acceptance" do
142
142
 
143
143
  it "saves a new env_run_lists" do
144
144
  target.env_run_lists = env_run_lists = {
145
- production: ["recipe[one]"],
146
- development: ["recipe[two]"]
145
+ "production" => ["recipe[one]"],
146
+ "development" => ["recipe[two]"]
147
147
  }
148
148
 
149
149
  connection.sync do
@@ -167,9 +167,9 @@ describe "Role API operations", type: "acceptance" do
167
167
 
168
168
  it "saves a new default_attributes" do
169
169
  target.default_attributes = defaults = {
170
- attribute_one: "value_one",
171
- nested: {
172
- other: false
170
+ "attribute_one" => "value_one",
171
+ "nested" => {
172
+ "other" => false
173
173
  }
174
174
  }
175
175
 
@@ -183,9 +183,9 @@ describe "Role API operations", type: "acceptance" do
183
183
 
184
184
  it "saves a new override_attributes" do
185
185
  target.override_attributes = overrides = {
186
- attribute_two: "value_two",
187
- nested: {
188
- other: false
186
+ "attribute_two" => "value_two",
187
+ "nested" => {
188
+ "other" => false
189
189
  }
190
190
  }
191
191
 
@@ -22,9 +22,10 @@ describe "Search API operations", type: "acceptance" do
22
22
  it "returns an array of indexes" do
23
23
  indexes = connection.search_indexes
24
24
 
25
- indexes.should include(:role)
26
- indexes.should include(:node)
27
- indexes.should include(:client)
25
+ indexes.should include("role")
26
+ indexes.should include("node")
27
+ indexes.should include("client")
28
+ indexes.should include("environment")
28
29
  end
29
30
  end
30
31
 
@@ -10,27 +10,27 @@ describe Ridley::DataBagItem do
10
10
  context "when JSON has a 'raw_data' field" do
11
11
  let(:response) do
12
12
  {
13
- name: "data_bag_item_ridley-test_appconfig",
14
- raw_data: {
15
- id: "appconfig",
16
- host: "host.local"
13
+ "name" => "data_bag_item_ridley-test_appconfig",
14
+ "raw_data" => {
15
+ "id" => "appconfig",
16
+ "host" => "host.local"
17
17
  },
18
- json_class: "Chef::DataBagItem",
19
- data_bag: "ridley-test",
20
- chef_type: "data_bag_item"
18
+ "json_class" => "Chef::DataBagItem",
19
+ "data_bag" => "ridley-test",
20
+ "chef_type" => "data_bag_item"
21
21
  }
22
22
  end
23
23
 
24
24
  it "returns a new object from attributes in the 'raw_data' field" do
25
- subject.from_hash(response).attributes.should eql(response[:raw_data])
25
+ subject.from_hash(response).attributes.should eql(response["raw_data"])
26
26
  end
27
27
  end
28
28
 
29
29
  context "when JSON does not contain a 'raw_data' field" do
30
30
  let(:response) do
31
31
  {
32
- id: "appconfig",
33
- host: "host.local"
32
+ "id" => "appconfig",
33
+ "host" => "host.local"
34
34
  }
35
35
  end
36
36
 
@@ -144,4 +144,36 @@ describe Ridley::Node do
144
144
  end
145
145
  end
146
146
  end
147
+
148
+ describe "#eucalyptus?" do
149
+ it "returns true if the eucalyptus automatic attribute is set" do
150
+ subject.automatic = {
151
+ "eucalyptus" => Hash.new
152
+ }
153
+
154
+ subject.eucalyptus?.should be_true
155
+ end
156
+
157
+ it "returns false if the eucalyptus automatic attribute is not set" do
158
+ subject.automatic.delete(:eucalyptus)
159
+
160
+ subject.eucalyptus?.should be_false
161
+ end
162
+ end
163
+
164
+ describe "#ec2?" do
165
+ it "returns true if the ec2 automatic attribute is set" do
166
+ subject.automatic = {
167
+ "ec2" => Hash.new
168
+ }
169
+
170
+ subject.ec2?.should be_true
171
+ end
172
+
173
+ it "returns false if the ec2 automatic attribute is not set" do
174
+ subject.automatic.delete(:ec2)
175
+
176
+ subject.ec2?.should be_false
177
+ end
178
+ end
147
179
  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.1.0
4
+ version: 0.2.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-09 00:00:00.000000000 Z
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chozo
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.0.2
21
+ version: 0.0.3
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.0.2
29
+ version: 0.0.3
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: yajl-ruby
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -434,7 +434,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
434
434
  version: '0'
435
435
  segments:
436
436
  - 0
437
- hash: 1428878148981436287
437
+ hash: 1117487299346141240
438
438
  requirements: []
439
439
  rubyforge_project:
440
440
  rubygems_version: 1.8.23