cfoundry 0.3.56 → 0.3.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -163,7 +163,7 @@ module CFoundry
163
163
  nil
164
164
  # return request headers (not really Accept)
165
165
  else
166
- raise "unknown mimetype #{content.inspect}"
166
+ raise CFoundry::Error, "Unknown mimetype '#{content.inspect}'"
167
167
  end
168
168
  end
169
169
 
@@ -317,7 +317,9 @@ module CFoundry
317
317
  when Net::HTTPSuccess, Net::HTTPRedirection
318
318
  if accept == :json
319
319
  if response.is_a?(Net::HTTPNoContent)
320
- raise "Expected JSON response, got 204 No Content"
320
+ raise CFoundry::BadResponse.new(
321
+ 204,
322
+ "Expected JSON response, got 204 No Content")
321
323
  end
322
324
 
323
325
  parse_json(response.body)
@@ -1,4 +1,20 @@
1
1
  module CFoundry
2
+ # Base class for CFoundry errors (not from the server).
3
+ class Error < RuntimeError; end
4
+
5
+ class Deprecated < Error; end
6
+
7
+ class Mismatch < Error
8
+ def initialize(expected, got)
9
+ @expected = expected
10
+ @got = got
11
+ end
12
+
13
+ def to_s
14
+ "Invalid value type; expected #{@expected.inspect}, got #{@got.inspect}"
15
+ end
16
+ end
17
+
2
18
  # Exception representing errors returned by the API.
3
19
  class APIError < RuntimeError
4
20
  class << self
@@ -64,7 +64,9 @@ module CFoundry
64
64
  when Net::HTTPSuccess, Net::HTTPRedirection
65
65
  if accept == :json
66
66
  if response.is_a?(Net::HTTPNoContent)
67
- raise "Expected JSON response, got 204 No Content"
67
+ raise CFoundry::BadResponse.new(
68
+ 204,
69
+ "Expected JSON response, got 204 No Content")
68
70
  end
69
71
 
70
72
  parse_json(response.body)
@@ -88,7 +88,8 @@ module CFoundry
88
88
 
89
89
  unless unreachable.empty?
90
90
  root = Pathname.new(path).relative_path_from(pwd)
91
- raise "Can't deploy application containing links '#{unreachable}' that reach outside its root '#{root}'"
91
+ raise CFoundry::Error,
92
+ "Path contains links '#{unreachable}' that point outside '#{root}'"
92
93
  end
93
94
  end
94
95
 
@@ -360,7 +360,7 @@ module CFoundry::V1
360
360
  # Only do this if you know what you're doing.
361
361
  def upload(path, check_resources = true)
362
362
  unless File.exist? path
363
- raise "invalid application path '#{path}'"
363
+ raise CFoundry::Error, "Invalid application path '#{path}'"
364
364
  end
365
365
 
366
366
  zipfile = "#{Dir.tmpdir}/#{@name}.zip"
@@ -159,7 +159,9 @@ module CFoundry::V1
159
159
  when Net::HTTPSuccess, Net::HTTPRedirection
160
160
  if accept == :json
161
161
  if response.is_a?(Net::HTTPNoContent)
162
- raise "Expected JSON response, got 204 No Content"
162
+ raise CFoundry::BadResponse.new(
163
+ 204,
164
+ "Expected JSON response, got 204 No Content")
163
165
  end
164
166
 
165
167
  parse_json(response.body)
@@ -127,7 +127,8 @@ module CFoundry::V2
127
127
  alias :urls :uris
128
128
 
129
129
  def uris=(uris)
130
- raise "App#uris= is invalid against V2 APIs. Use add/remove_route."
130
+ raise CFoundry::Deprecated,
131
+ "App#uris= is invalid against V2 APIs; use add/remove_route"
131
132
  end
132
133
  alias :urls= :uris=
133
134
 
@@ -140,7 +141,9 @@ module CFoundry::V2
140
141
  d.name == domain_name
141
142
  }
142
143
 
143
- raise "Invalid domain '#{domain_name}'" unless domain
144
+ unless domain
145
+ raise CFoundry::Error, "Invalid domain '#{domain_name}'"
146
+ end
144
147
 
145
148
  route = @client.routes.find { |r|
146
149
  r.host == host && r.domain == domain
@@ -296,7 +299,7 @@ module CFoundry::V2
296
299
  # Only do this if you know what you're doing.
297
300
  def upload(path, check_resources = true)
298
301
  unless File.exist? path
299
- raise "invalid application path '#{path}'"
302
+ raise CFoundry::Error, "Invalid application path '#{path}'"
300
303
  end
301
304
 
302
305
  zipfile = "#{Dir.tmpdir}/#{@guid}.zip"
@@ -149,7 +149,9 @@ module CFoundry::V2
149
149
 
150
150
  if accept == :json
151
151
  if response.is_a?(Net::HTTPNoContent)
152
- raise "Expected JSON response, got 204 No Content"
152
+ raise CFoundry::BadResponse.new(
153
+ 204,
154
+ "Expected JSON response, got 204 No Content")
153
155
  end
154
156
 
155
157
  parse_json(response.body)
@@ -33,7 +33,7 @@ module CFoundry::V2
33
33
 
34
34
  def validate_type(val, type)
35
35
  unless value_matches?(val, type)
36
- raise "invalid attribute; expected #{type.inspect} but got #{val.inspect}"
36
+ raise CFoundry::Mismatch.new(type, val)
37
37
  end
38
38
  end
39
39
 
@@ -62,13 +62,13 @@ module CFoundry::V2
62
62
  defaults[name] = default
63
63
  end
64
64
 
65
- define_method(name) {
65
+ define_method(name) do
66
66
  return @cache[name] if @cache.key?(name)
67
67
 
68
68
  @cache[name] = manifest[:entity][name] || default
69
- }
69
+ end
70
70
 
71
- define_method(:"#{name}=") { |val|
71
+ define_method(:"#{name}=") do |val|
72
72
  unless has_default && val == default
73
73
  Model.validate_type(val, type)
74
74
  end
@@ -79,7 +79,7 @@ module CFoundry::V2
79
79
  @manifest[:entity] ||= {}
80
80
  @manifest[:entity][name] = val
81
81
  @diff[name] = val
82
- }
82
+ end
83
83
  end
84
84
 
85
85
  def scoped_to_organization(relation = :organization)
@@ -104,7 +104,7 @@ module CFoundry::V2
104
104
  defaults[:"#{name}_guid"] = default
105
105
  end
106
106
 
107
- define_method(name) {
107
+ define_method(name) do
108
108
  return @cache[name] if @cache.key?(name)
109
109
 
110
110
  @cache[name] =
@@ -115,13 +115,13 @@ module CFoundry::V2
115
115
  else
116
116
  default
117
117
  end
118
- }
118
+ end
119
119
 
120
- define_method(:"#{name}_url") {
120
+ define_method(:"#{name}_url") do
121
121
  manifest[:entity][:"#{name}_url"]
122
- }
122
+ end
123
123
 
124
- define_method(:"#{name}=") { |x|
124
+ define_method(:"#{name}=") do |x|
125
125
  unless has_default && x == default
126
126
  Model.validate_type(x, CFoundry::V2.const_get(kls))
127
127
  end
@@ -132,7 +132,7 @@ module CFoundry::V2
132
132
  @manifest[:entity] ||= {}
133
133
  @manifest[:entity][:"#{name}_guid"] =
134
134
  @diff[:"#{name}_guid"] = x && x.guid
135
- }
135
+ end
136
136
  end
137
137
 
138
138
  def to_many(plural, opts = {})
@@ -147,7 +147,7 @@ module CFoundry::V2
147
147
  $1 + $2.upcase
148
148
  end
149
149
 
150
- define_method(plural) { |*args|
150
+ define_method(plural) do |*args|
151
151
  depth, query = args
152
152
 
153
153
  if !depth && !query && cache = @cache[plural]
@@ -181,13 +181,13 @@ module CFoundry::V2
181
181
  end
182
182
 
183
183
  res
184
- }
184
+ end
185
185
 
186
- define_method(:"#{plural}_url") {
186
+ define_method(:"#{plural}_url") do
187
187
  manifest[:entity][:"#{plural}_url"]
188
- }
188
+ end
189
189
 
190
- define_method(:"add_#{singular}") { |x|
190
+ define_method(:"add_#{singular}") do |x|
191
191
  Model.validate_type(x, CFoundry::V2.const_get(kls))
192
192
 
193
193
  if cache = @cache[plural]
@@ -198,9 +198,9 @@ module CFoundry::V2
198
198
  Net::HTTP::Put,
199
199
  ["v2", "#{object_name}s", @guid, plural, x.guid],
200
200
  :accept => :json)
201
- }
201
+ end
202
202
 
203
- define_method(:"remove_#{singular}") { |x|
203
+ define_method(:"remove_#{singular}") do |x|
204
204
  Model.validate_type(x, CFoundry::V2.const_get(kls))
205
205
 
206
206
  if cache = @cache[plural]
@@ -211,9 +211,9 @@ module CFoundry::V2
211
211
  Net::HTTP::Delete,
212
212
  ["v2", "#{object_name}s", @guid, plural, x.guid],
213
213
  :accept => :json)
214
- }
214
+ end
215
215
 
216
- define_method(:"#{plural}=") { |xs|
216
+ define_method(:"#{plural}=") do |xs|
217
217
  Model.validate_type(xs, [CFoundry::V2.const_get(kls)])
218
218
 
219
219
  @cache[plural] = xs
@@ -222,7 +222,7 @@ module CFoundry::V2
222
222
  @manifest[:entity] ||= {}
223
223
  @manifest[:entity][:"#{singular}_guids"] =
224
224
  @diff[:"#{singular}_guids"] = xs.collect(&:guid)
225
- }
225
+ end
226
226
  end
227
227
 
228
228
  def has_summary(actions = {})
@@ -248,11 +248,11 @@ module CFoundry::V2
248
248
  elsif self.class.to_many_relations[key]
249
249
  singular = key.to_s.sub(/s$/, "").to_sym
250
250
 
251
- vals = val.collect { |sub|
251
+ vals = val.collect do |sub|
252
252
  obj = @client.send(singular, sub[:guid], true)
253
253
  obj.summarize! sub
254
254
  obj
255
- }
255
+ end
256
256
 
257
257
  self.send(:"#{key}=", vals)
258
258
 
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.56"
3
+ VERSION = "0.3.57"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 99
4
+ hash: 97
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 56
10
- version: 0.3.56
9
+ - 57
10
+ version: 0.3.57
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-10 00:00:00 -08:00
18
+ date: 2012-11-11 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency