cfoundry 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module CFoundry::V2
7
7
  class Model
8
8
  extend ModelMagic
9
9
 
10
- attr_accessor :guid, :cache
10
+ attr_accessor :guid, :cache, :changes
11
11
 
12
12
  def initialize(guid, client, manifest = nil, partial = false)
13
13
  @guid = guid
@@ -16,6 +16,7 @@ module CFoundry::V2
16
16
  @partial = partial
17
17
  @cache = {}
18
18
  @diff = {}
19
+ @changes = {}
19
20
  end
20
21
 
21
22
  def manifest
@@ -26,6 +27,10 @@ module CFoundry::V2
26
27
  @partial
27
28
  end
28
29
 
30
+ def changed?
31
+ !@changes.empty?
32
+ end
33
+
29
34
  def inspect
30
35
  "\#<#{self.class.name} '#@guid'>"
31
36
  end
@@ -39,6 +44,7 @@ module CFoundry::V2
39
44
  @partial = false
40
45
  @cache = {}
41
46
  @diff = {}
47
+ @changes = {}
42
48
  end
43
49
 
44
50
  # this does a bit of extra processing to allow for
@@ -157,7 +157,11 @@ module CFoundry::V2
157
157
 
158
158
  @manifest ||= {}
159
159
  @manifest[:entity] ||= {}
160
+
161
+ old = @manifest[:entity][name]
162
+ @changes[name] = [old, val] if old != val
160
163
  @manifest[:entity][name] = val
164
+
161
165
  @diff[name] = val
162
166
  end
163
167
  end
@@ -201,17 +205,28 @@ module CFoundry::V2
201
205
  manifest[:entity][:"#{name}_url"]
202
206
  end
203
207
 
204
- define_method(:"#{name}=") do |x|
205
- unless has_default && x == default
206
- ModelMagic.validate_type(x, CFoundry::V2.const_get(kls))
207
- end
208
+ define_method(:"#{name}=") do |val|
209
+ klass = CFoundry::V2.const_get(kls)
208
210
 
209
- @cache[name] = x
211
+ unless has_default && val == default
212
+ ModelMagic.validate_type(val, klass)
213
+ end
210
214
 
211
215
  @manifest ||= {}
212
216
  @manifest[:entity] ||= {}
217
+
218
+ old = @manifest[:entity][:"#{name}_guid"]
219
+ if old != val.guid
220
+ old_obj = klass.new(@client, old, @manifest[:entity][name])
221
+
222
+ @changes[name] = [old_obj, val]
223
+ end
224
+
225
+ @cache[name] = val
226
+
227
+ @manifest[:entity][name] = val.manifest
213
228
  @manifest[:entity][:"#{name}_guid"] =
214
- @diff[:"#{name}_guid"] = x && x.guid
229
+ @diff[:"#{name}_guid"] = val && val.guid
215
230
  end
216
231
  end
217
232
 
@@ -295,12 +310,29 @@ module CFoundry::V2
295
310
  end
296
311
 
297
312
  define_method(:"#{plural}=") do |xs|
298
- ModelMagic.validate_type(xs, [CFoundry::V2.const_get(kls)])
313
+ klass = CFoundry::V2.const_get(kls)
299
314
 
300
- @cache[plural] = xs
315
+ ModelMagic.validate_type(xs, [klass])
301
316
 
302
317
  @manifest ||= {}
303
318
  @manifest[:entity] ||= {}
319
+
320
+ old = @manifest[:entity][:"#{singular}_guids"]
321
+ if old != xs.collect(&:guid)
322
+ old_objs =
323
+ if all = @manifest[:entity][plural]
324
+ all.collect do |m|
325
+ klass.new(@client, m[:metadata][:guid], m)
326
+ end
327
+ else
328
+ old.collect { |id| klass.new(@client, id) }
329
+ end
330
+
331
+ @changes[name] = [old_objs, val]
332
+ end
333
+
334
+ @cache[plural] = xs
335
+
304
336
  @manifest[:entity][:"#{singular}_guids"] =
305
337
  @diff[:"#{singular}_guids"] = xs.collect(&:guid)
306
338
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.4.2".freeze
3
+ VERSION = "0.4.3".freeze
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: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 2
10
- version: 0.4.2
9
+ - 3
10
+ version: 0.4.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-30 00:00:00 -08:00
19
- default_executable:
18
+ date: 2012-12-05 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: multipart-post
@@ -111,44 +110,43 @@ extra_rdoc_files: []
111
110
  files:
112
111
  - LICENSE
113
112
  - Rakefile
114
- - lib/cfoundry.rb
113
+ - lib/cfoundry/baseclient.rb
114
+ - lib/cfoundry/chatty_hash.rb
115
115
  - lib/cfoundry/client.rb
116
- - lib/cfoundry/version.rb
117
116
  - lib/cfoundry/errors.rb
118
117
  - lib/cfoundry/uaaclient.rb
119
- - lib/cfoundry/v2/service_binding.rb
120
- - lib/cfoundry/v2/service.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
121
129
  - lib/cfoundry/v2/client.rb
122
- - lib/cfoundry/v2/model.rb
123
- - lib/cfoundry/v2/user.rb
130
+ - lib/cfoundry/v2/domain.rb
124
131
  - lib/cfoundry/v2/framework.rb
132
+ - lib/cfoundry/v2/model.rb
125
133
  - lib/cfoundry/v2/model_magic.rb
126
- - lib/cfoundry/v2/service_auth_token.rb
127
- - lib/cfoundry/v2/space.rb
128
- - lib/cfoundry/v2/app.rb
129
- - lib/cfoundry/v2/service_plan.rb
130
- - lib/cfoundry/v2/base.rb
131
134
  - lib/cfoundry/v2/organization.rb
132
135
  - lib/cfoundry/v2/route.rb
133
- - lib/cfoundry/v2/domain.rb
134
136
  - lib/cfoundry/v2/runtime.rb
137
+ - lib/cfoundry/v2/service.rb
138
+ - lib/cfoundry/v2/service_auth_token.rb
139
+ - lib/cfoundry/v2/service_binding.rb
135
140
  - lib/cfoundry/v2/service_instance.rb
136
- - lib/cfoundry/baseclient.rb
137
- - lib/cfoundry/upload_helpers.rb
138
- - lib/cfoundry/v1/service.rb
139
- - lib/cfoundry/v1/client.rb
140
- - lib/cfoundry/v1/user.rb
141
- - lib/cfoundry/v1/framework.rb
142
- - lib/cfoundry/v1/app.rb
143
- - lib/cfoundry/v1/base.rb
144
- - lib/cfoundry/v1/runtime.rb
145
- - lib/cfoundry/v1/service_instance.rb
141
+ - lib/cfoundry/v2/service_plan.rb
142
+ - lib/cfoundry/v2/space.rb
143
+ - lib/cfoundry/v2/user.rb
144
+ - lib/cfoundry/version.rb
146
145
  - lib/cfoundry/zip.rb
147
- - lib/cfoundry/chatty_hash.rb
146
+ - lib/cfoundry.rb
147
+ - spec/client_spec.rb
148
148
  - spec/helpers.rb
149
149
  - spec/Rakefile
150
- - spec/client_spec.rb
151
- has_rdoc: true
152
150
  homepage: http://cloudfoundry.com/
153
151
  licenses: []
154
152
 
@@ -178,11 +176,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
176
  requirements: []
179
177
 
180
178
  rubyforge_project: cfoundry
181
- rubygems_version: 1.6.2
179
+ rubygems_version: 1.8.24
182
180
  signing_key:
183
181
  specification_version: 3
184
182
  summary: High-level library for working with the Cloud Foundry API.
185
183
  test_files:
184
+ - spec/client_spec.rb
186
185
  - spec/helpers.rb
187
186
  - spec/Rakefile
188
- - spec/client_spec.rb