nested 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nested.rb +19 -4
- data/nested.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e094093ea980a578d78107c00f909441725de662
|
4
|
+
data.tar.gz: 4313216ddde4c3e9a20b4bea403e28a62d6755c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c424d4769683d24f933508a2974d410871dca9325d05d3dba0471c551d30de68c8b914402d638e7f555d22e13aa3a74a86fe339b659aede851999fe51cb6db05
|
7
|
+
data.tar.gz: 41e439448d8985bc7e70d5cf905b8d4ceafe6730c86e2e9dea9e23317ee24613f2830d505d2bcaf53ac66ba16222764bc0b9740f76d3498e1a4cdbae5af1df6a
|
data/lib/nested.rb
CHANGED
@@ -14,6 +14,13 @@ module Nested
|
|
14
14
|
class NameMissingError < StandardError
|
15
15
|
end
|
16
16
|
|
17
|
+
class Redirect
|
18
|
+
attr_reader :url
|
19
|
+
def initialize(url)
|
20
|
+
@url = url
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
17
24
|
class Resource
|
18
25
|
FETCH = -> do
|
19
26
|
raise "implement fetch for resource #{@__resource.name}" unless @__resource.parent
|
@@ -47,7 +54,7 @@ module Nested
|
|
47
54
|
init &-> do
|
48
55
|
fetched = instance_exec(&(init_block||FETCH))
|
49
56
|
|
50
|
-
puts "set @#{@__resource.instance_variable_name} to #{fetched.inspect} for #{self}"
|
57
|
+
# puts "set @#{@__resource.instance_variable_name} to #{fetched.inspect} for #{self}"
|
51
58
|
self.instance_variable_set("@#{@__resource.instance_variable_name}", fetched)
|
52
59
|
end
|
53
60
|
|
@@ -214,7 +221,7 @@ module Nested
|
|
214
221
|
end
|
215
222
|
|
216
223
|
def sinatra_response_type(response)
|
217
|
-
(response.is_a?(ActiveModel::Errors) || (response.respond_to?(:errors) && !response.errors.empty?)) ? :error : :data
|
224
|
+
(response.is_a?(ActiveModel::Errors) || (response.respond_to?(:errors) && !response.errors.empty?)) ? :error : (response.is_a?(Nested::Redirect) ? :redirect : :data)
|
218
225
|
end
|
219
226
|
|
220
227
|
def sinatra_response(sinatra, method)
|
@@ -222,11 +229,19 @@ module Nested
|
|
222
229
|
response = self.send(:"sinatra_response_create_#{sinatra_response_type(response)}", sinatra, response, method)
|
223
230
|
|
224
231
|
case response
|
225
|
-
when
|
226
|
-
|
232
|
+
when Nested::Redirect then
|
233
|
+
sinatra.redirect(response.url)
|
234
|
+
when String then
|
235
|
+
response
|
236
|
+
else
|
237
|
+
response.to_json
|
227
238
|
end
|
228
239
|
end
|
229
240
|
|
241
|
+
def sinatra_response_create_redirect(sinatra, response, method)
|
242
|
+
response
|
243
|
+
end
|
244
|
+
|
230
245
|
def sinatra_response_create_data(sinatra, response, method)
|
231
246
|
data = if response && collection? && method != :post
|
232
247
|
response.to_a.map{|e| sinatra.instance_exec(e, &@__serialize) }
|
data/nested.gemspec
CHANGED