cfoundry 0.3.41 → 0.3.42

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,6 +33,8 @@ module CFoundry::V2
33
33
  to_many :service_bindings
34
34
  to_many :routes
35
35
 
36
+ scoped_to_space
37
+
36
38
  alias :total_instances :instances
37
39
  alias :total_instances= :instances=
38
40
 
@@ -150,21 +150,41 @@ module CFoundry::V2
150
150
 
151
151
  klass = CFoundry::V2.const_get(classname)
152
152
 
153
- has_space = klass.method_defined? :space
153
+ scoped_organization = klass.scoped_organization
154
+ scoped_space = klass.scoped_space
155
+
154
156
  has_name = klass.method_defined? :name
155
157
 
156
158
  define_method(singular) do |*args|
157
159
  guid, _ = args
158
- klass.new(guid, self)
160
+
161
+ x = klass.new(guid, self)
162
+
163
+ # when creating an object, automatically set the org/space
164
+ unless guid
165
+ if scoped_organization && current_organization
166
+ x.send(:"#{scoped_organization}=", current_organization)
167
+ end
168
+
169
+ if scoped_space && current_space
170
+ x.send(:"#{scoped_space}=", current_space)
171
+ end
172
+ end
173
+
174
+ x
159
175
  end
160
176
 
161
177
  define_method(plural) do |*args|
162
178
  depth, query = args
163
179
  depth ||= 1
164
180
 
165
- if has_space && current_space
181
+ # use current org/space
182
+ if scoped_space && current_space
183
+ query ||= {}
184
+ query[:"#{scoped_space}_guid"] ||= current_space.guid
185
+ elsif scoped_organization && current_organization
166
186
  query ||= {}
167
- query[:space_guid] ||= current_space.guid
187
+ query[:"#{scoped_organization}_guid"] ||= current_organization.guid
168
188
  end
169
189
 
170
190
  @base.send(plural, depth, query).collect do |json|
@@ -177,8 +197,11 @@ module CFoundry::V2
177
197
  depth, _ = args
178
198
  depth ||= 1
179
199
 
180
- if has_space && current_space
200
+ # use current org/space
201
+ if scoped_space && current_space
181
202
  current_space.send(plural, depth, :name => name).first
203
+ elsif scoped_organization && current_organization
204
+ current_organization.send(plural, depth, :name => name).first
182
205
  else
183
206
  send(plural, depth, :name => name).first
184
207
  end
@@ -4,5 +4,7 @@ module CFoundry::V2
4
4
  class Domain < Model
5
5
  attribute :name, :string
6
6
  to_one :owning_organization, :as => :organization
7
+
8
+ scoped_to_organization :owning_organization
7
9
  end
8
10
  end
@@ -3,6 +3,8 @@ require "multi_json"
3
3
  module CFoundry::V2
4
4
  class Model
5
5
  class << self
6
+ attr_reader :scoped_organization, :scoped_space
7
+
6
8
  def value_matches?(val, type)
7
9
  case type
8
10
  when Class
@@ -61,6 +63,14 @@ module CFoundry::V2
61
63
  }
62
64
  end
63
65
 
66
+ def scoped_to_organization(relation = :organization)
67
+ @scoped_organization = relation
68
+ end
69
+
70
+ def scoped_to_space(relation = :space)
71
+ @scoped_space = relation
72
+ end
73
+
64
74
  def to_one(name, opts = {})
65
75
  obj = opts[:as] || name
66
76
  kls = obj.to_s.capitalize.gsub(/(.)_(.)/) do
@@ -5,5 +5,7 @@ module CFoundry::V2
5
5
  attribute :host, :string
6
6
  to_one :domain
7
7
  to_one :organization
8
+
9
+ scoped_to_organization
8
10
  end
9
11
  end
@@ -6,5 +6,7 @@ module CFoundry::V2
6
6
  to_one :space
7
7
  to_one :service_plan
8
8
  to_many :service_bindings
9
+
10
+ scoped_to_space
9
11
  end
10
12
  end
@@ -10,5 +10,7 @@ module CFoundry::V2
10
10
  to_many :apps
11
11
  to_many :domains
12
12
  to_many :service_instances
13
+
14
+ scoped_to_organization
13
15
  end
14
16
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.41"
3
+ VERSION = "0.3.42"
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: 65
4
+ hash: 71
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 41
10
- version: 0.3.41
9
+ - 42
10
+ version: 0.3.42
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-10-11 00:00:00 Z
18
+ date: 2012-10-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client