cfoundry 0.3.8 → 0.3.9

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.
@@ -321,18 +321,22 @@ module CFoundry::V1
321
321
 
322
322
 
323
323
  # Bind services to application.
324
- def bind(*service_names)
325
- update!(:services => services + service_names)
324
+ def bind(*instances)
325
+ update!(:services => services + instances.collect(&:name))
326
326
  end
327
327
 
328
328
  # Unbind services from application.
329
- def unbind(*service_names)
329
+ def unbind(*instances)
330
330
  update!(:services =>
331
331
  services.reject { |s|
332
- service_names.include?(s)
332
+ instances.any? { |i| i.name == s }
333
333
  })
334
334
  end
335
335
 
336
+ def binds?(instance)
337
+ services.any? { |s| s == instance.name }
338
+ end
339
+
336
340
  # Retrieve file listing under path for the first instance of the application.
337
341
  #
338
342
  # [path]
@@ -33,11 +33,12 @@ module CFoundry::V2
33
33
  alias :total_instances :instances
34
34
  alias :total_instances= :instances=
35
35
 
36
- alias :services :service_bindings
37
- alias :services= :service_bindings=
38
-
39
36
  private :environment_json, :environment_json=
40
37
 
38
+ def services
39
+ service_bindings.collect(&:service_instance)
40
+ end
41
+
41
42
  def env
42
43
  @env ||= CFoundry::ChattyHash.new(
43
44
  method(:env=),
@@ -50,10 +51,17 @@ module CFoundry::V2
50
51
  hash
51
52
  end
52
53
 
54
+ def command # TODO v2
55
+ nil
56
+ end
57
+
53
58
  def debug_mode # TODO v2
54
59
  nil
55
60
  end
56
- alias :console :debug_mode
61
+
62
+ def console # TODO v2
63
+ nil
64
+ end
57
65
 
58
66
  def uris # TODO v2
59
67
  []
@@ -118,16 +126,33 @@ module CFoundry::V2
118
126
  end
119
127
 
120
128
  # Bind services to application.
121
- def bind(*service_names)
122
- update!(:services => services + service_names)
129
+ def bind(*instances)
130
+ instances.each do |i|
131
+ binding = @client.service_binding
132
+ binding.app = self
133
+ binding.service_instance = i
134
+ binding.credentials = {} # ?
135
+ binding.create!
136
+ end
137
+
138
+ self
123
139
  end
124
140
 
125
141
  # Unbind services from application.
126
- def unbind(*service_names)
127
- update!(:services =>
128
- services.reject { |s|
129
- service_names.include?(s)
130
- })
142
+ def unbind(*instances)
143
+ service_bindings.each do |b|
144
+ if instances.include? b.service_instance
145
+ b.delete!
146
+ end
147
+ end
148
+
149
+ self
150
+ end
151
+
152
+ def binds?(instance)
153
+ service_bindings.any? { |b|
154
+ b.service_instance == instance
155
+ }
131
156
  end
132
157
  end
133
158
  end
@@ -25,8 +25,8 @@ module CFoundry::V2
25
25
  obj = opts[:as] || name
26
26
 
27
27
  define_method(name) {
28
- if manifest[:entity].key? name
29
- @client.send(:"make_#{obj}", manifest[:entity][name])
28
+ if @manifest && @manifest[:entity].key?(name)
29
+ @client.send(:"make_#{obj}", @manifest[:entity][name])
30
30
  else
31
31
  @client.send(
32
32
  :"#{obj}_from",
@@ -56,8 +56,8 @@ module CFoundry::V2
56
56
  define_method(plural) { |*args|
57
57
  depth, query = args
58
58
 
59
- if manifest[:entity].key?(plural)
60
- objs = manifest[:entity][plural]
59
+ if @manifest && @manifest[:entity].key?(plural) && !depth
60
+ objs = @manifest[:entity][plural]
61
61
 
62
62
  if query
63
63
  find_by = query.keys.first
@@ -71,7 +71,7 @@ module CFoundry::V2
71
71
  else
72
72
  @client.send(
73
73
  :"#{plural_object}_from",
74
- send("#{plural}_url"),
74
+ "/v2/#{object_name}s/#@guid/#{plural}",
75
75
  depth || opts[:depth],
76
76
  query)
77
77
  end
@@ -130,26 +130,58 @@ module CFoundry::V2
130
130
  '\1_\2').downcase
131
131
  end
132
132
 
133
+ # this does a bit of extra processing to allow for
134
+ # `delete!' followed by `create!'
133
135
  def create!
134
- @manifest =
135
- @client.base.send(
136
- :"create_#{object_name}",
137
- self.class.defaults.merge(@manifest[:entity]))
136
+ payload = {}
137
+
138
+ self.class.defaults.merge(@manifest[:entity]).each do |k, v|
139
+ if v.is_a?(Hash) && v.key?(:metadata)
140
+ # skip; there's a _guid attribute already
141
+ elsif v.is_a?(Array) && v.all? { |x|
142
+ x.is_a?(Hash) && x.key?(:metadata)
143
+ }
144
+ singular = k.to_s.sub(/s$/, "")
145
+
146
+ payload[:"#{singular}_guids"] = v.collect do |x|
147
+ if x.is_a?(Hash) && x.key?(:metadata)
148
+ x[:metadata][:guid]
149
+ else
150
+ x
151
+ end
152
+ end
153
+ elsif k.to_s.end_with?("_json") && v.is_a?(String)
154
+ payload[k] = JSON.parse(v)
155
+ elsif k.to_s.end_with?("_url")
156
+ else
157
+ payload[k] = v
158
+ end
159
+ end
160
+
161
+ @manifest = @client.base.send(:"create_#{object_name}", payload)
138
162
 
139
163
  @guid = @manifest[:metadata][:guid]
140
164
 
165
+ @diff.clear
166
+
141
167
  true
142
168
  end
143
169
 
144
170
  def update!(diff = @diff)
145
171
  @client.base.send(:"update_#{object_name}", @guid, diff)
146
172
 
173
+ @diff.clear if diff == @diff
174
+
147
175
  @manifest = nil
148
176
  end
149
177
 
150
178
  def delete!
151
179
  @client.base.send(:"delete_#{object_name}", @guid)
152
180
 
181
+ @guid = nil
182
+
183
+ @diff.clear
184
+
153
185
  if @manifest
154
186
  @manifest.delete :metadata
155
187
  end
@@ -162,8 +194,13 @@ module CFoundry::V2
162
194
  false
163
195
  end
164
196
 
165
- def ==(other)
197
+ def eql?(other)
166
198
  other.is_a?(self.class) && @guid == other.guid
167
199
  end
200
+ alias :== :eql?
201
+
202
+ def hash
203
+ @guid.hash
204
+ end
168
205
  end
169
206
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.8"
3
+ VERSION = "0.3.9"
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 8
10
- version: 0.3.8
9
+ - 9
10
+ version: 0.3.9
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-07-19 00:00:00 Z
18
+ date: 2012-07-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client