nested 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nested.rb +19 -4
  3. data/nested.gemspec +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08311b441f9f650ce485cd6f5e628c76c20af3a8
4
- data.tar.gz: d701b6f2c978ef0d457ba2c2f8d7071fe8320c14
3
+ metadata.gz: e094093ea980a578d78107c00f909441725de662
4
+ data.tar.gz: 4313216ddde4c3e9a20b4bea403e28a62d6755c8
5
5
  SHA512:
6
- metadata.gz: 7531556331af1d8770ced5c4bd5a16098be0fa8eef9509a97cd494b18bb21da1d26d8c5c9dd7c59e70eb106ab604c49f20f6992e6e28801ac7a894fa259c1af0
7
- data.tar.gz: 0c4b3c81cfbff503df6efa4febe0d0df3d154797251a86f4f22774e67ebc594f12e8142df1a03f52eb09278940579bf31378a275da7d7c1220fa93eb74b91180
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 String then response
226
- else response.to_json
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "nested"
3
- s.version = "0.0.15"
3
+ s.version = "0.0.16"
4
4
 
5
5
  s.authors = ["Jan Zimmek"]
6
6
  s.email = %q{jan.zimmek@web.de}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zimmek