cfoundry 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -187,6 +187,9 @@ module CFoundry::V1
187
187
  App.new(name, self)
188
188
  end
189
189
 
190
+ # TODO: remove once v2 allows filtering by name
191
+ # see V2::Client#app_by_name
192
+ alias :app_by_name :app
190
193
 
191
194
  # Retrieve all of the current user's services.
192
195
  def service_instances
@@ -46,8 +46,9 @@ module CFoundry::V2
46
46
  end
47
47
 
48
48
 
49
- [:app, :organization, :app_space, :service, :service_instance,
50
- :user, :runtime, :framework].each do |obj|
49
+ [ :app, :organization, :app_space, :user, :runtime, :framework,
50
+ :service, :service_plan, :service_binding, :service_instance
51
+ ].each do |obj|
51
52
  plural = "#{obj}s"
52
53
 
53
54
  define_method(obj) do |guid, *args|
@@ -5,7 +5,9 @@ require "cfoundry/v2/framework"
5
5
  require "cfoundry/v2/organization"
6
6
  require "cfoundry/v2/runtime"
7
7
  require "cfoundry/v2/service"
8
+ require "cfoundry/v2/service_binding"
8
9
  require "cfoundry/v2/service_instance"
10
+ require "cfoundry/v2/service_plan"
9
11
  require "cfoundry/v2/space"
10
12
  require "cfoundry/v2/user"
11
13
 
@@ -113,14 +115,26 @@ module CFoundry::V2
113
115
  end
114
116
 
115
117
 
116
- [:app, :organization, :app_space, :service, :service_binding,
117
- :service_instance, :user, :runtime, :framework].each do |singular|
118
+ # TODO: allow direct filtering
119
+ def app_by_name(name)
120
+ current_space.apps.find do |a|
121
+ a.name == name
122
+ end
123
+ end
124
+
125
+
126
+ [ :app, :organization, :app_space, :user, :runtime, :framework,
127
+ :service, :service_plan, :service_binding, :service_instance
128
+ ].each do |singular|
118
129
  klass = singular.to_s.capitalize.gsub(/(.)_(.)/) do
119
130
  $1 + $2.upcase
120
131
  end
121
132
 
122
133
  plural = :"#{singular}s"
123
134
 
135
+ has_app_space =
136
+ CFoundry::V2.const_get(klass).method_defined? :app_space
137
+
124
138
  define_method(singular) do |*args|
125
139
  id, _ = args
126
140
  CFoundry::V2.const_get(klass).new(id, self)
@@ -130,6 +144,11 @@ module CFoundry::V2
130
144
  depth, query = args
131
145
  depth ||= 1
132
146
 
147
+ if has_app_space
148
+ query ||= {}
149
+ query[:app_space_guid] ||= current_space.id
150
+ end
151
+
133
152
  @base.send(plural, depth, query)[:resources].collect do |json|
134
153
  send(:"make_#{singular}", json)
135
154
  end
@@ -17,6 +17,7 @@ module CFoundry::V2
17
17
  @manifest ||= {}
18
18
  @manifest[:entity] ||= {}
19
19
  @manifest[:entity][name] = val
20
+ @diff[name] = val
20
21
  }
21
22
  end
22
23
 
@@ -38,7 +39,8 @@ module CFoundry::V2
38
39
  define_method(:"#{name}=") { |x|
39
40
  @manifest ||= {}
40
41
  @manifest[:entity] ||= {}
41
- @manifest[:entity][:"#{name}_guid"] = x.id
42
+ @manifest[:entity][:"#{name}_guid"] =
43
+ @diff[:"#{name}_guid"] = x.id
42
44
  }
43
45
  end
44
46
 
@@ -78,7 +80,8 @@ module CFoundry::V2
78
80
  define_method(:"#{plural}=") { |xs|
79
81
  @manifest ||= {}
80
82
  @manifest[:entity] ||= {}
81
- @manifest[:entity][:"#{singular}_guids"] = xs.collect(&:id)
83
+ @manifest[:entity][:"#{singular}_guids"] =
84
+ @diff[:"#{singular}_guids"] = xs.collect(&:id)
82
85
  }
83
86
  end
84
87
  end
@@ -89,6 +92,7 @@ module CFoundry::V2
89
92
  @id = id
90
93
  @client = client
91
94
  @manifest = manifest
95
+ @diff = {}
92
96
  end
93
97
 
94
98
  def manifest
@@ -118,11 +122,8 @@ module CFoundry::V2
118
122
  true
119
123
  end
120
124
 
121
- def update!(diff = nil)
122
- @client.base.send(
123
- :"update_#{object_name}",
124
- @id,
125
- diff || manifest[:entity])
125
+ def update!(diff = @diff)
126
+ @client.base.send(:"update_#{object_name}", @id, diff)
126
127
 
127
128
  @manifest = nil
128
129
  end
@@ -0,0 +1,11 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class ServiceBinding < Model
5
+ attribute :credentials
6
+ attribute :binding_options, :default => {}
7
+ attribute :vendor_data, :default => {}
8
+ to_one :app
9
+ to_one :service_instance
10
+ end
11
+ end
@@ -8,5 +8,8 @@ module CFoundry::V2
8
8
  to_many :service_bindings
9
9
  attribute :credentials
10
10
  attribute :vendor_data, :default => ""
11
+
12
+ alias :space :app_space
13
+ alias :space= :app_space=
11
14
  end
12
15
  end
@@ -9,5 +9,6 @@ module CFoundry::V2
9
9
  to_many :auditors, :as => :user
10
10
  to_many :apps
11
11
  to_many :domains
12
+ to_many :service_instances
12
13
  end
13
14
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
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-13 00:00:00 Z
18
+ date: 2012-07-14 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client
@@ -126,6 +126,7 @@ files:
126
126
  - lib/cfoundry/v2/organization.rb
127
127
  - lib/cfoundry/v2/runtime.rb
128
128
  - lib/cfoundry/v2/service.rb
129
+ - lib/cfoundry/v2/service_binding.rb
129
130
  - lib/cfoundry/v2/service_instance.rb
130
131
  - lib/cfoundry/v2/service_plan.rb
131
132
  - lib/cfoundry/v2/space.rb