roda-rest_api 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af55d203299440b1fdc7d6335ddeab64a6aeefd8
4
- data.tar.gz: 8496c4b5081bced31212a7df915b2f63e0cb399a
3
+ metadata.gz: 80e8b5e484fe53a1f4fb788f1b626588dd4267d6
4
+ data.tar.gz: 330493a7f67ce9f21f23622c9e7f6959d5ba68f3
5
5
  SHA512:
6
- metadata.gz: 51b812a5f7c860fa7fcb49f4725d85114f43b6fdf42ef17b88a87a38e74859990467c1e02a498f78d2002c8cbb352dc32ee6af341eeb9cbe8b41b66d2f14e5d7
7
- data.tar.gz: b5a781123357311c3e9060c67aa09bc84b01014fca83aa05f78a4469803091317f08162cc155e40e4eaaae861d8f2911c0a8f964ad341b21167046e28a678eb0
6
+ metadata.gz: b131711f5a1d500221c2830f63eba6b2c79a0494a3ed365a4ec4fa1c0453115fa7bd58d153a48c4f91d17009eeb23fce675b4062b3c1618bd04ec3e638cb3c07
7
+ data.tar.gz: 526075155bf5c1662de80353a5826df7a44bf99e1a4dcf5cc82b0168150d554069d50dd098ad7ee67470cb5736fd35a02fd5a08b524ec38382e42e1a1062dee3
@@ -14,7 +14,8 @@ class Roda
14
14
 
15
15
  class Resource
16
16
 
17
- attr_reader :request, :path, :singleton, :content_type, :parent, :captures
17
+ attr_reader :request, :path, :singleton, :content_type, :parent
18
+ attr_accessor :captures
18
19
 
19
20
  def initialize(path, request, parent, options={})
20
21
  @request = request
@@ -24,10 +25,9 @@ class Roda
24
25
  @primary_key = options.delete(:primary_key) || "id"
25
26
  @parent_key = options.delete(:parent_key) || "parent_id"
26
27
  @content_type = options.delete(:content_type) || APPLICATION_JSON
27
- if parent && !@request.script_name.empty?
28
+ if parent
28
29
  @parent = parent
29
30
  @parent.routes!
30
- @captures = @request.captures.dup
31
31
  @path = [':d', @path].join('/') unless bare
32
32
  end
33
33
  end
@@ -73,9 +73,10 @@ class Roda
73
73
  begin
74
74
  args = method === :save ? JSON.parse(@request.body) : @request.GET
75
75
  args.merge!(@primary_key => id) if id
76
- args.merge!(@parent_key => @captures[0]) if @parent && !@captures.empty?
76
+ args.merge!(@parent_key => @captures[0]) if @captures
77
77
  self.send(method).call(args)
78
78
  rescue StandardError => e
79
+ raise if ENV['RACK_ENV'] == 'development'
79
80
  @request.response.status = method === :save ? 422 : 404
80
81
  end
81
82
  end
@@ -98,6 +99,7 @@ class Roda
98
99
  def resource(path, options={})
99
100
  @resource = Resource.new(path, self, @resource, options)
100
101
  on(@resource.path, options) do
102
+ @resource.captures = captures.dup unless captures.empty?
101
103
  yield @resource
102
104
  @resource.routes!
103
105
  response.status = 404
data/lib/roda/rest_api.rb CHANGED
@@ -1,6 +1,2 @@
1
1
  require 'roda'
2
2
  require 'roda/plugins/rest_api'
3
-
4
- class Roda
5
- plugin :rest_api
6
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-rest_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Benevento