cfoundry 0.3.54 → 0.3.55

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ module CFoundry::V2
27
27
  attribute :instances, :integer, :default => 1
28
28
  attribute :file_descriptors, :integer, :default => 256
29
29
  attribute :disk_quota, :integer, :default => 256
30
- attribute :state, :integer, :default => "STOPPED"
30
+ attribute :state, :string, :default => "STOPPED"
31
31
  attribute :command, :string, :default => nil
32
32
  attribute :console, :boolean, :default => false
33
33
  to_many :service_bindings
@@ -35,6 +35,43 @@ module CFoundry::V2
35
35
 
36
36
  scoped_to_space
37
37
 
38
+ has_summary :urls => proc { |x| self.cache[:uris] = x },
39
+ :running_instances => proc { |x|
40
+ self.cache[:running_instances] = x
41
+ },
42
+
43
+ # TODO: remove these when cc consistently returns nested hashes
44
+ :framework_guid => proc { |x|
45
+ if f = self.cache[:framework]
46
+ f.guid = x
47
+ else
48
+ self.framework = @client.framework(x, true)
49
+ end
50
+ },
51
+ :framework_name => proc { |x|
52
+ if f = self.cache[:framework]
53
+ f.name = x
54
+ else
55
+ self.framework = @client.framework(nil, true)
56
+ self.framework.name = x
57
+ end
58
+ },
59
+ :runtime_guid => proc { |x|
60
+ if f = self.cache[:runtime]
61
+ f.guid = x
62
+ else
63
+ self.runtime = @client.runtime(x, true)
64
+ end
65
+ },
66
+ :runtime_name => proc { |x|
67
+ if f = self.cache[:runtime]
68
+ f.name = x
69
+ else
70
+ self.runtime = @client.runtime(nil, true)
71
+ self.runtime.name = x
72
+ end
73
+ }
74
+
38
75
  alias :total_instances :instances
39
76
  alias :total_instances= :instances=
40
77
 
@@ -81,6 +118,8 @@ module CFoundry::V2
81
118
  end
82
119
 
83
120
  def uris
121
+ return @cache[:uris] if @cache[:uris]
122
+
84
123
  routes.collect do |r|
85
124
  "#{r.host}.#{r.domain.name}"
86
125
  end
@@ -121,6 +160,10 @@ module CFoundry::V2
121
160
  alias :create_route :create_routes
122
161
 
123
162
  def uri
163
+ if uris = @cache[:uris]
164
+ return uris.first
165
+ end
166
+
124
167
  if route = routes.first
125
168
  "#{route.host}.#{route.domain.name}"
126
169
  end
@@ -175,6 +218,8 @@ module CFoundry::V2
175
218
  end
176
219
 
177
220
  def running_instances
221
+ return @cache[:running_instances] if @cache[:running_instances]
222
+
178
223
  running = 0
179
224
 
180
225
  instances.each do |i|
@@ -166,9 +166,9 @@ module CFoundry::V2
166
166
  has_name = klass.method_defined? :name
167
167
 
168
168
  define_method(singular) do |*args|
169
- guid, _ = args
169
+ guid, partial, _ = args
170
170
 
171
- x = klass.new(guid, self)
171
+ x = klass.new(guid, self, nil, partial)
172
172
 
173
173
  # when creating an object, automatically set the org/space
174
174
  unless guid
@@ -41,7 +41,21 @@ module CFoundry::V2
41
41
  @defaults ||= {}
42
42
  end
43
43
 
44
+ def attributes
45
+ @attributes ||= {}
46
+ end
47
+
48
+ def to_one_relations
49
+ @to_one_relations ||= {}
50
+ end
51
+
52
+ def to_many_relations
53
+ @to_many_relations ||= {}
54
+ end
55
+
44
56
  def attribute(name, type, opts = {})
57
+ attributes[name] = opts
58
+
45
59
  default = opts[:default]
46
60
 
47
61
  if has_default = opts.key?(:default)
@@ -49,7 +63,9 @@ module CFoundry::V2
49
63
  end
50
64
 
51
65
  define_method(name) {
52
- manifest[:entity][name] || default
66
+ return @cache[name] if @cache.key?(name)
67
+
68
+ @cache[name] = manifest[:entity][name] || default
53
69
  }
54
70
 
55
71
  define_method(:"#{name}=") { |val|
@@ -57,6 +73,8 @@ module CFoundry::V2
57
73
  Model.validate_type(val, type)
58
74
  end
59
75
 
76
+ @cache[name] = val
77
+
60
78
  @manifest ||= {}
61
79
  @manifest[:entity] ||= {}
62
80
  @manifest[:entity][name] = val
@@ -73,6 +91,8 @@ module CFoundry::V2
73
91
  end
74
92
 
75
93
  def to_one(name, opts = {})
94
+ to_one_relations[name] = opts
95
+
76
96
  obj = opts[:as] || name
77
97
  kls = obj.to_s.capitalize.gsub(/(.)_(.)/) do
78
98
  $1 + $2.upcase
@@ -85,13 +105,16 @@ module CFoundry::V2
85
105
  end
86
106
 
87
107
  define_method(name) {
88
- if @manifest && @manifest[:entity].key?(name)
89
- @client.send(:"make_#{obj}", @manifest[:entity][name])
90
- elsif url = send("#{name}_url")
91
- @client.send(:"#{obj}_from", url, opts[:depth] || 1)
92
- else
93
- default
94
- end
108
+ return @cache[name] if @cache.key?(name)
109
+
110
+ @cache[name] =
111
+ if @manifest && @manifest[:entity].key?(name)
112
+ @client.send(:"make_#{obj}", @manifest[:entity][name])
113
+ elsif url = send("#{name}_url")
114
+ @client.send(:"#{obj}_from", url, opts[:depth] || 1)
115
+ else
116
+ default
117
+ end
95
118
  }
96
119
 
97
120
  define_method(:"#{name}_url") {
@@ -103,6 +126,8 @@ module CFoundry::V2
103
126
  Model.validate_type(x, CFoundry::V2.const_get(kls))
104
127
  end
105
128
 
129
+ @cache[name] = x
130
+
106
131
  @manifest ||= {}
107
132
  @manifest[:entity] ||= {}
108
133
  @manifest[:entity][:"#{name}_guid"] =
@@ -111,6 +136,8 @@ module CFoundry::V2
111
136
  end
112
137
 
113
138
  def to_many(plural, opts = {})
139
+ to_many_relations[plural] = opts
140
+
114
141
  singular = plural.to_s.sub(/s$/, "").to_sym
115
142
 
116
143
  object = opts[:as] || singular
@@ -121,6 +148,10 @@ module CFoundry::V2
121
148
  end
122
149
 
123
150
  define_method(plural) { |*args|
151
+ if cache = @cache[plural]
152
+ return cache
153
+ end
154
+
124
155
  depth, query = args
125
156
 
126
157
  if @manifest && @manifest[:entity].key?(plural) && !depth
@@ -132,15 +163,17 @@ module CFoundry::V2
132
163
  objs = objs.select { |o| o[:entity][find_by] == find_val }
133
164
  end
134
165
 
135
- objs.collect do |json|
136
- @client.send(:"make_#{object}", json)
137
- end
166
+ @cache[plural] =
167
+ objs.collect do |json|
168
+ @client.send(:"make_#{object}", json)
169
+ end
138
170
  else
139
- @client.send(
140
- :"#{plural_object}_from",
141
- "/v2/#{object_name}s/#@guid/#{plural}",
142
- depth || opts[:depth],
143
- query)
171
+ @cache[plural] =
172
+ @client.send(
173
+ :"#{plural_object}_from",
174
+ "/v2/#{object_name}s/#@guid/#{plural}",
175
+ depth || opts[:depth],
176
+ query)
144
177
  end
145
178
  }
146
179
 
@@ -149,9 +182,12 @@ module CFoundry::V2
149
182
  }
150
183
 
151
184
  define_method(:"add_#{singular}") { |x|
152
- # TODO: reflect this change in the app manifest?
153
185
  Model.validate_type(x, CFoundry::V2.const_get(kls))
154
186
 
187
+ if cache = @cache[plural]
188
+ cache << x unless cache.include?(x)
189
+ end
190
+
155
191
  @client.base.request_path(
156
192
  Net::HTTP::Put,
157
193
  ["v2", "#{object_name}s", @guid, plural, x.guid],
@@ -159,9 +195,12 @@ module CFoundry::V2
159
195
  }
160
196
 
161
197
  define_method(:"remove_#{singular}") { |x|
162
- # TODO: reflect this change in the app manifest?
163
198
  Model.validate_type(x, CFoundry::V2.const_get(kls))
164
199
 
200
+ if cache = @cache[plural]
201
+ cache.delete(x)
202
+ end
203
+
165
204
  @client.base.request_path(
166
205
  Net::HTTP::Delete,
167
206
  ["v2", "#{object_name}s", @guid, plural, x.guid],
@@ -171,20 +210,67 @@ module CFoundry::V2
171
210
  define_method(:"#{plural}=") { |xs|
172
211
  Model.validate_type(xs, [CFoundry::V2.const_get(kls)])
173
212
 
213
+ @cache[plural] = xs
214
+
174
215
  @manifest ||= {}
175
216
  @manifest[:entity] ||= {}
176
217
  @manifest[:entity][:"#{singular}_guids"] =
177
218
  @diff[:"#{singular}_guids"] = xs.collect(&:guid)
178
219
  }
179
220
  end
221
+
222
+ def has_summary(actions = {})
223
+ define_method(:summary) do
224
+ @client.base.request_path(
225
+ Net::HTTP::Get,
226
+ ["v2", "#{object_name}s", @guid, "summary"],
227
+ :accept => :json)
228
+ end
229
+
230
+ define_method(:summarize!) do |*args|
231
+ body, _ = args
232
+
233
+ body ||= summary
234
+
235
+ body.each do |key, val|
236
+ if act = actions[key]
237
+ instance_exec(val, &act)
238
+
239
+ elsif self.class.attributes[key]
240
+ self.send(:"#{key}=", val)
241
+
242
+ elsif self.class.to_many_relations[key]
243
+ singular = key.to_s.sub(/s$/, "").to_sym
244
+
245
+ vals = val.collect { |sub|
246
+ obj = @client.send(singular, sub[:guid], true)
247
+ obj.summarize! sub
248
+ obj
249
+ }
250
+
251
+ self.send(:"#{key}=", vals)
252
+
253
+ elsif self.class.to_one_relations[key]
254
+ obj = @client.send(key, val[:guid], true)
255
+ obj.summarize! val
256
+
257
+ self.send(:"#{key}=", obj)
258
+ end
259
+ end
260
+
261
+ nil
262
+ end
263
+ end
180
264
  end
181
265
 
182
- attr_reader :guid
266
+ attr_accessor :guid, :cache
183
267
 
184
- def initialize(guid, client, manifest = nil)
268
+ def initialize(guid, client, manifest = nil, partial = false)
185
269
  @guid = guid
186
270
  @client = client
187
271
  @manifest = manifest
272
+ @partial = partial
273
+ @cache = {}
188
274
  @diff = {}
189
275
  end
190
276
 
@@ -192,6 +278,10 @@ module CFoundry::V2
192
278
  @manifest ||= @client.base.send(object_name, @guid)
193
279
  end
194
280
 
281
+ def partial?
282
+ @partial
283
+ end
284
+
195
285
  def inspect
196
286
  "\#<#{self.class.name} '#@guid'>"
197
287
  end
@@ -205,6 +295,8 @@ module CFoundry::V2
205
295
 
206
296
  def invalidate!
207
297
  @manifest = nil
298
+ @partial = false
299
+ @cache = {}
208
300
  @diff = {}
209
301
  end
210
302
 
@@ -12,5 +12,7 @@ module CFoundry::V2
12
12
  to_many :service_instances
13
13
 
14
14
  scoped_to_organization
15
+
16
+ has_summary
15
17
  end
16
18
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.54"
3
+ VERSION = "0.3.55"
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: 127
4
+ hash: 125
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 54
10
- version: 0.3.54
9
+ - 55
10
+ version: 0.3.55
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-07 00:00:00 Z
18
+ date: 2012-11-10 00:00:00 -08:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: multipart-post
@@ -110,42 +111,43 @@ extra_rdoc_files: []
110
111
  files:
111
112
  - LICENSE
112
113
  - Rakefile
113
- - lib/cfoundry/baseclient.rb
114
- - lib/cfoundry/chatty_hash.rb
114
+ - lib/cfoundry.rb
115
115
  - lib/cfoundry/client.rb
116
+ - lib/cfoundry/version.rb
116
117
  - lib/cfoundry/errors.rb
117
118
  - lib/cfoundry/uaaclient.rb
118
- - lib/cfoundry/upload_helpers.rb
119
- - lib/cfoundry/v1/app.rb
120
- - lib/cfoundry/v1/base.rb
121
- - lib/cfoundry/v1/client.rb
122
- - lib/cfoundry/v1/framework.rb
123
- - lib/cfoundry/v1/runtime.rb
124
- - lib/cfoundry/v1/service.rb
125
- - lib/cfoundry/v1/service_instance.rb
126
- - lib/cfoundry/v1/user.rb
127
- - lib/cfoundry/v2/app.rb
128
- - lib/cfoundry/v2/base.rb
119
+ - lib/cfoundry/v2/service_binding.rb
120
+ - lib/cfoundry/v2/service.rb
129
121
  - lib/cfoundry/v2/client.rb
130
- - lib/cfoundry/v2/domain.rb
131
- - lib/cfoundry/v2/framework.rb
132
122
  - lib/cfoundry/v2/model.rb
123
+ - lib/cfoundry/v2/user.rb
124
+ - lib/cfoundry/v2/framework.rb
125
+ - lib/cfoundry/v2/service_auth_token.rb
126
+ - lib/cfoundry/v2/space.rb
127
+ - lib/cfoundry/v2/app.rb
128
+ - lib/cfoundry/v2/service_plan.rb
129
+ - lib/cfoundry/v2/base.rb
133
130
  - lib/cfoundry/v2/organization.rb
134
131
  - lib/cfoundry/v2/route.rb
132
+ - lib/cfoundry/v2/domain.rb
135
133
  - lib/cfoundry/v2/runtime.rb
136
- - lib/cfoundry/v2/service.rb
137
- - lib/cfoundry/v2/service_auth_token.rb
138
- - lib/cfoundry/v2/service_binding.rb
139
134
  - lib/cfoundry/v2/service_instance.rb
140
- - lib/cfoundry/v2/service_plan.rb
141
- - lib/cfoundry/v2/space.rb
142
- - lib/cfoundry/v2/user.rb
143
- - lib/cfoundry/version.rb
135
+ - lib/cfoundry/baseclient.rb
136
+ - lib/cfoundry/upload_helpers.rb
137
+ - lib/cfoundry/v1/service.rb
138
+ - lib/cfoundry/v1/client.rb
139
+ - lib/cfoundry/v1/user.rb
140
+ - lib/cfoundry/v1/framework.rb
141
+ - lib/cfoundry/v1/app.rb
142
+ - lib/cfoundry/v1/base.rb
143
+ - lib/cfoundry/v1/runtime.rb
144
+ - lib/cfoundry/v1/service_instance.rb
144
145
  - lib/cfoundry/zip.rb
145
- - lib/cfoundry.rb
146
- - spec/client_spec.rb
146
+ - lib/cfoundry/chatty_hash.rb
147
147
  - spec/helpers.rb
148
148
  - spec/Rakefile
149
+ - spec/client_spec.rb
150
+ has_rdoc: true
149
151
  homepage: http://cloudfoundry.com/
150
152
  licenses: []
151
153
 
@@ -175,11 +177,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
177
  requirements: []
176
178
 
177
179
  rubyforge_project: cfoundry
178
- rubygems_version: 1.8.24
180
+ rubygems_version: 1.6.2
179
181
  signing_key:
180
182
  specification_version: 3
181
183
  summary: High-level library for working with the Cloud Foundry API.
182
184
  test_files:
183
- - spec/client_spec.rb
184
185
  - spec/helpers.rb
185
186
  - spec/Rakefile
187
+ - spec/client_spec.rb