cfoundry 0.3.7 → 0.3.8
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.
- data/lib/cfoundry/baseclient.rb +2 -1
- data/lib/cfoundry/v2/base.rb +12 -7
- data/lib/cfoundry/v2/client.rb +23 -39
- data/lib/cfoundry/v2/model.rb +15 -4
- data/lib/cfoundry/version.rb +1 -1
- metadata +3 -3
data/lib/cfoundry/baseclient.rb
CHANGED
data/lib/cfoundry/v2/base.rb
CHANGED
@@ -74,17 +74,22 @@ module CFoundry::V2
|
|
74
74
|
end
|
75
75
|
|
76
76
|
define_method(plural) do |*args|
|
77
|
-
|
78
|
-
|
77
|
+
get("v2", plural, nil => :json, :params => params_from(args))
|
78
|
+
end
|
79
|
+
end
|
79
80
|
|
80
|
-
params = { :"inline-relations-depth" => depth }
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
def params_from(args)
|
83
|
+
depth, query = args
|
84
|
+
depth ||= 1
|
85
|
+
|
86
|
+
params = { :"inline-relations-depth" => depth }
|
85
87
|
|
86
|
-
|
88
|
+
if query
|
89
|
+
params[:q] = "#{query.keys.first}:#{query.values.first}"
|
87
90
|
end
|
91
|
+
|
92
|
+
params
|
88
93
|
end
|
89
94
|
|
90
95
|
private
|
data/lib/cfoundry/v2/client.rb
CHANGED
@@ -115,29 +115,23 @@ module CFoundry::V2
|
|
115
115
|
end
|
116
116
|
|
117
117
|
|
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
118
|
[ :app, :organization, :space, :user, :runtime, :framework,
|
127
119
|
:service, :service_plan, :service_binding, :service_instance
|
128
120
|
].each do |singular|
|
129
|
-
|
121
|
+
plural = :"#{singular}s"
|
122
|
+
|
123
|
+
classname = singular.to_s.capitalize.gsub(/(.)_(.)/) do
|
130
124
|
$1 + $2.upcase
|
131
125
|
end
|
132
126
|
|
133
|
-
|
127
|
+
klass = CFoundry::V2.const_get(classname)
|
134
128
|
|
135
|
-
has_space =
|
136
|
-
|
129
|
+
has_space = klass.method_defined? :space
|
130
|
+
has_name = klass.method_defined? :name
|
137
131
|
|
138
132
|
define_method(singular) do |*args|
|
139
133
|
guid, _ = args
|
140
|
-
|
134
|
+
klass.new(guid, self)
|
141
135
|
end
|
142
136
|
|
143
137
|
define_method(plural) do |*args|
|
@@ -154,48 +148,38 @@ module CFoundry::V2
|
|
154
148
|
end
|
155
149
|
end
|
156
150
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
uri.query += "&inline-relations-depth=#{depth}"
|
165
|
-
else
|
166
|
-
uri.query = "inline-relations-depth=#{depth}"
|
151
|
+
if has_name
|
152
|
+
define_method(:"#{singular}_by_name") do |name|
|
153
|
+
if has_space && current_space
|
154
|
+
current_space.send(plural, 1, :name => name).first
|
155
|
+
else
|
156
|
+
send(plural, 1, :name => name).first
|
157
|
+
end
|
167
158
|
end
|
159
|
+
end
|
168
160
|
|
161
|
+
define_method(:"#{singular}_from") do |path, *args|
|
169
162
|
send(
|
170
163
|
:"make_#{singular}",
|
171
164
|
@base.request_path(
|
172
165
|
:get,
|
173
|
-
|
174
|
-
nil => :json
|
166
|
+
path,
|
167
|
+
nil => :json,
|
168
|
+
:params => @base.params_from(args)))
|
175
169
|
end
|
176
170
|
|
177
171
|
define_method(:"#{plural}_from") do |path, *args|
|
178
|
-
depth, _ = args
|
179
|
-
depth ||= 1
|
180
|
-
|
181
|
-
uri = URI.parse(path)
|
182
|
-
|
183
|
-
if uri.query
|
184
|
-
uri.query += "&inline-relations-depth=#{depth}"
|
185
|
-
else
|
186
|
-
uri.query = "inline-relations-depth=#{depth}"
|
187
|
-
end
|
188
|
-
|
189
172
|
@base.request_path(
|
190
173
|
:get,
|
191
|
-
|
192
|
-
nil => :json
|
174
|
+
path,
|
175
|
+
nil => :json,
|
176
|
+
:params => @base.params_from(args))[:resources].collect do |json|
|
193
177
|
send(:"make_#{singular}", json)
|
194
178
|
end
|
195
179
|
end
|
196
180
|
|
197
181
|
define_method(:"make_#{singular}") do |json|
|
198
|
-
|
182
|
+
klass.new(
|
199
183
|
json[:metadata][:guid],
|
200
184
|
self,
|
201
185
|
json)
|
data/lib/cfoundry/v2/model.rb
CHANGED
@@ -53,16 +53,27 @@ module CFoundry::V2
|
|
53
53
|
object = opts[:as] || singular
|
54
54
|
plural_object = :"#{object}s"
|
55
55
|
|
56
|
-
define_method(plural) {
|
57
|
-
|
58
|
-
|
56
|
+
define_method(plural) { |*args|
|
57
|
+
depth, query = args
|
58
|
+
|
59
|
+
if manifest[:entity].key?(plural)
|
60
|
+
objs = manifest[:entity][plural]
|
61
|
+
|
62
|
+
if query
|
63
|
+
find_by = query.keys.first
|
64
|
+
find_val = query.values.first
|
65
|
+
objs = objs.select { |o| o[:entity][find_by] == find_val }
|
66
|
+
end
|
67
|
+
|
68
|
+
objs.collect do |json|
|
59
69
|
@client.send(:"make_#{object}", json)
|
60
70
|
end
|
61
71
|
else
|
62
72
|
@client.send(
|
63
73
|
:"#{plural_object}_from",
|
64
74
|
send("#{plural}_url"),
|
65
|
-
opts[:depth]
|
75
|
+
depth || opts[:depth],
|
76
|
+
query)
|
66
77
|
end
|
67
78
|
}
|
68
79
|
|
data/lib/cfoundry/version.rb
CHANGED
metadata
CHANGED