grape-rabl 0.4.3 → 0.5.0
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.
- checksums.yaml +5 -5
- data/.rubocop_todo.yml +15 -9
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -4
- data/README.md +7 -7
- data/Rakefile +1 -1
- data/UPGRADING.md +32 -0
- data/grape-rabl.gemspec +3 -3
- data/lib/grape-rabl/formatter.rb +7 -1
- data/lib/grape-rabl/version.rb +1 -1
- data/spec/grape_rabl_formatter_spec.rb +84 -0
- data/spec/views/_partial.rabl +1 -1
- data/spec/views/admin.rabl +1 -1
- data/spec/views/info.rabl +1 -1
- data/spec/views/project.rabl +3 -3
- data/spec/views/user.rabl +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2139e066606a02ff9f13f498209f8b67b9edee1f17aa6765b0cdd0f304bf16e6
|
4
|
+
data.tar.gz: 3f026c83de19ed9c97ec5169dda8e4e9a7c52e5f977befa61a085ef3df07767b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a468e3a080bc6485c48ad71066d2dab882b2541e579cfe8bea3e644b1118bf91e1400184d03ed3d29ff01062449cf85e034aa9f7a56b0ebeedfb4d5c05c5565d
|
7
|
+
data.tar.gz: 49b59dfc17187e747844c375cfbf1d805f0158786141a8910516f0945108171475c11ffc31d7788ad59fd80c7650abefbf519e12437cd8bc3b25e1378b8d7413
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2017-11-17 09:51:46 -0500 using RuboCop version 0.51.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -11,8 +11,13 @@ Lint/RescueException:
|
|
11
11
|
Exclude:
|
12
12
|
- 'spec/grape_rabl_spec.rb'
|
13
13
|
|
14
|
-
# Offense count:
|
15
|
-
# Configuration parameters:
|
14
|
+
# Offense count: 8
|
15
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
16
|
+
Metrics/BlockLength:
|
17
|
+
Max: 169
|
18
|
+
|
19
|
+
# Offense count: 23
|
20
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
16
21
|
# URISchemes: http, https
|
17
22
|
Metrics/LineLength:
|
18
23
|
Max: 148
|
@@ -22,6 +27,13 @@ Metrics/LineLength:
|
|
22
27
|
Metrics/MethodLength:
|
23
28
|
Max: 13
|
24
29
|
|
30
|
+
# Offense count: 1
|
31
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
32
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
33
|
+
Naming/FileName:
|
34
|
+
Exclude:
|
35
|
+
- 'lib/grape-rabl.rb'
|
36
|
+
|
25
37
|
# Offense count: 5
|
26
38
|
Style/Documentation:
|
27
39
|
Exclude:
|
@@ -38,12 +50,6 @@ Style/DoubleNegation:
|
|
38
50
|
Exclude:
|
39
51
|
- 'lib/grape-rabl/formatter.rb'
|
40
52
|
|
41
|
-
# Offense count: 1
|
42
|
-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
|
43
|
-
Style/FileName:
|
44
|
-
Exclude:
|
45
|
-
- 'lib/grape-rabl.rb'
|
46
|
-
|
47
53
|
# Offense count: 1
|
48
54
|
Style/IfInsideElse:
|
49
55
|
Exclude:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
#### v0.5.0
|
2
|
+
|
3
|
+
* [#34](https://github.com/ruby-grape/grape-rabl/pulls/34): If no RABL template is specified, fallback to the default response format as determined by Grape - [@chrisbloom7](https://github.com/chrisbloom7).
|
4
|
+
|
1
5
|
#### v0.4.3
|
2
6
|
|
3
7
|
* [#44](https://github.com/ruby-grape/grape-rabl/issues/44): Don't require unused hashie - [@tsuwatch](https://github.com/tsuwatch).
|
data/Gemfile
CHANGED
@@ -3,15 +3,15 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development do
|
6
|
-
gem 'rubocop', '0.
|
6
|
+
gem 'rubocop', '0.51.0'
|
7
7
|
end
|
8
8
|
|
9
9
|
group :test do
|
10
|
+
gem 'coveralls', require: false
|
10
11
|
gem 'json'
|
11
|
-
gem '
|
12
|
+
gem 'rabl'
|
12
13
|
gem 'rack-test'
|
13
14
|
gem 'rake'
|
14
|
-
gem '
|
15
|
-
gem 'rabl'
|
15
|
+
gem 'rspec'
|
16
16
|
gem 'ruby-grape-danger', '~> 0.1.1', require: false
|
17
17
|
end
|
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# Grape::Rabl
|
2
2
|
|
3
|
-
Use [Rabl](https://github.com/nesquena/rabl) templates in [Grape](https://github.com/
|
3
|
+
Use [Rabl](https://github.com/nesquena/rabl) templates in [Grape](https://github.com/ruby-grape/grape)!
|
4
4
|
|
5
5
|
[](http://badge.fury.io/rb/grape-rabl)
|
6
6
|
[](https://travis-ci.org/ruby-grape/grape-rabl)
|
7
|
-
[](https://gemnasium.com/ruby-grape/grape-rabl)
|
8
7
|
[](https://codeclimate.com/github/ruby-grape/grape-rabl)
|
9
8
|
[](https://coveralls.io/r/ruby-grape/grape-rabl?branch=master)
|
10
9
|
|
@@ -21,6 +20,10 @@ And then execute:
|
|
21
20
|
|
22
21
|
$ bundle
|
23
22
|
|
23
|
+
## Upgrading
|
24
|
+
|
25
|
+
See [UPGRADING](UPGRADING.md).
|
26
|
+
|
24
27
|
## Usage
|
25
28
|
|
26
29
|
### Setup view root directory
|
@@ -135,7 +138,7 @@ class UserAPI < Grape::API
|
|
135
138
|
@history = User.find(params[:id]).history
|
136
139
|
end
|
137
140
|
|
138
|
-
# do not use rabl, fallback to the
|
141
|
+
# do not use rabl, fallback to the default Grape response formatter
|
139
142
|
get '/users' do
|
140
143
|
User.all
|
141
144
|
end
|
@@ -191,13 +194,10 @@ end
|
|
191
194
|
|
192
195
|
## Specs
|
193
196
|
|
194
|
-
See ["Writing Tests"](https://github.com/
|
197
|
+
See ["Writing Tests"](https://github.com/ruby-grape/grape#writing-tests) in [grape](https://github.com/ruby-grape/grape) README.
|
195
198
|
|
196
199
|
Enjoy :)
|
197
200
|
|
198
201
|
## Contributing
|
199
202
|
|
200
203
|
See [CONTRIBUTING](CONTRIBUTING.md).
|
201
|
-
|
202
|
-
[](https://bitdeli.com/free "Bitdeli Badge")
|
203
|
-
|
data/Rakefile
CHANGED
data/UPGRADING.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Upgrading Grape::Rabl
|
2
|
+
|
3
|
+
## Upgrading to >= 0.5
|
4
|
+
|
5
|
+
### Fallback rendering when no RABL template is defined
|
6
|
+
|
7
|
+
Prior to v0.5.0, Grape::Rabl would always render content as JSON when no Rabl template was specified for a request. Beginning in v0.5.0 Grape::Rabl will now fallback to using the default response format [as determined by Grape](https://github.com/ruby-grape/grape#api-formats)
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class SampleApi < Grape::API
|
11
|
+
format :xml
|
12
|
+
formatter :xml, Grape::Formatter::Rabl
|
13
|
+
|
14
|
+
get 'list' do
|
15
|
+
%w[thing]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
#### Former behavior
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
response.body # => ["thing"]
|
24
|
+
```
|
25
|
+
|
26
|
+
#### Current behavior
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
response.body # => <?xml version="1.0" encoding="UTF-8"?>\n<strings type="array">\n <string>thing</string>\n</strings>
|
30
|
+
```
|
31
|
+
|
32
|
+
See [#34](https://github.com/ruby-grape/grape-rabl/pull/34) for more information.
|
data/grape-rabl.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
require File.expand_path('../lib/grape-rabl/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = [
|
5
|
+
gem.authors = ['Piotr Niełacny']
|
6
6
|
gem.email = ['piotr.nielacny@gmail.com']
|
7
7
|
gem.description = 'Use rabl in grape'
|
8
8
|
gem.summary = 'Use rabl in grape'
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.required_ruby_version = '>= 2.2.0'
|
18
18
|
|
19
19
|
gem.add_dependency 'grape'
|
20
|
+
gem.add_dependency 'i18n'
|
20
21
|
gem.add_dependency 'rabl'
|
21
22
|
gem.add_dependency 'tilt'
|
22
|
-
gem.add_dependency 'i18n'
|
23
23
|
end
|
data/lib/grape-rabl/formatter.rb
CHANGED
@@ -29,12 +29,18 @@ module Grape
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
else
|
32
|
-
|
32
|
+
fallback_formatter.call object, env
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
|
+
# Find a formatter to fallback to. `env[Grape::Env::API_FORMAT]` will always be a
|
39
|
+
# valid formatter, otherwise a HTTP 406 error would have already have been thrown
|
40
|
+
def fallback_formatter
|
41
|
+
Grape::Formatter.formatter_for(env[Grape::Env::API_FORMAT])
|
42
|
+
end
|
43
|
+
|
38
44
|
def view_path(template)
|
39
45
|
if template.split('.')[-1] == 'rabl'
|
40
46
|
File.join(env['api.tilt.root'], template)
|
data/lib/grape-rabl/version.rb
CHANGED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Grape::Rabl formatter' do
|
4
|
+
subject do
|
5
|
+
Class.new(Grape::API)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:xml_render) do
|
9
|
+
%(<?xml version="1.0" encoding="UTF-8"?>
|
10
|
+
<hash>
|
11
|
+
<errors type="array">
|
12
|
+
<error>bad</error>
|
13
|
+
<error>things</error>
|
14
|
+
<error>happened</error>
|
15
|
+
</errors>
|
16
|
+
</hash>
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def app
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'rendering' do
|
25
|
+
context 'when no rabl template is specified' do
|
26
|
+
before do
|
27
|
+
# Grape::API defaults to the following declarations:
|
28
|
+
# content_type :xml, 'application/xml'
|
29
|
+
# content_type :json, 'application/json'
|
30
|
+
# content_type :binary, 'application/octet-stream'
|
31
|
+
# content_type :txt, 'text/plain'
|
32
|
+
# default_format :txt
|
33
|
+
subject.formatter :xml, Grape::Formatter::Rabl
|
34
|
+
subject.formatter :txt, Grape::Formatter::Rabl
|
35
|
+
subject.get('/oops') { { errors: %w[bad things happened] } }
|
36
|
+
expect_any_instance_of(Grape::Rabl::Formatter).to receive(:render).and_call_original
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'falls back to :txt given no other format information' do
|
40
|
+
get '/oops'
|
41
|
+
expect(last_response.body).to eq('{:errors=>["bad", "things", "happened"]}')
|
42
|
+
expect(last_response.headers['Content-Type']).to eq('text/plain')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'falls back to the file extension if it is a valid format' do
|
46
|
+
get '/oops.xml'
|
47
|
+
expect(last_response.body).to eq(xml_render)
|
48
|
+
expect(last_response.headers['Content-Type']).to eq('application/xml')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'falls back to the value of the `format` parameter in the query string if it is provided' do
|
52
|
+
get '/oops?format=xml'
|
53
|
+
expect(last_response.body).to eq(xml_render)
|
54
|
+
expect(last_response.headers['Content-Type']).to eq('application/xml')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'falls back to the format set by the `format` option if it is a valid format' do
|
58
|
+
# `format` option must be declared before endpoint
|
59
|
+
subject.format :xml
|
60
|
+
subject.get('/oops/2') { { errors: %w[bad things happened] } }
|
61
|
+
|
62
|
+
get '/oops/2'
|
63
|
+
expect(last_response.body).to eq(xml_render)
|
64
|
+
expect(last_response.headers['Content-Type']).to eq('application/xml')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'falls back to the `Accept` header if it is a valid format' do
|
68
|
+
get '/oops', {}, 'HTTP_ACCEPT' => 'application/xml'
|
69
|
+
expect(last_response.body).to eq(xml_render)
|
70
|
+
expect(last_response.headers['Content-Type']).to eq('application/xml')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'falls back to the default_format option if it is a valid format' do
|
74
|
+
# `default_format` option must be declared before endpoint
|
75
|
+
subject.default_format :xml
|
76
|
+
subject.get('/oops/2') { { errors: %w[bad things happened] } }
|
77
|
+
|
78
|
+
get '/oops/2'
|
79
|
+
expect(last_response.body).to eq(xml_render)
|
80
|
+
expect(last_response.headers['Content-Type']).to eq('application/xml')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/spec/views/_partial.rabl
CHANGED
@@ -1 +1 @@
|
|
1
|
-
attributes :type
|
1
|
+
attributes :type
|
data/spec/views/admin.rabl
CHANGED
data/spec/views/info.rabl
CHANGED
@@ -1 +1 @@
|
|
1
|
-
attributes :author
|
1
|
+
attributes :author
|
data/spec/views/project.rabl
CHANGED
data/spec/views/user.rabl
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-rabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Niełacny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: i18n
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rabl
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: tilt
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- README.md
|
88
88
|
- RELEASING.md
|
89
89
|
- Rakefile
|
90
|
+
- UPGRADING.md
|
90
91
|
- grape-rabl.gemspec
|
91
92
|
- lib/grape-rabl.rb
|
92
93
|
- lib/grape-rabl/configuration.rb
|
@@ -96,6 +97,7 @@ files:
|
|
96
97
|
- lib/grape-rabl/version.rb
|
97
98
|
- lib/grape/rabl.rb
|
98
99
|
- spec/grape_rabl_configuration.rb
|
100
|
+
- spec/grape_rabl_formatter_spec.rb
|
99
101
|
- spec/grape_rabl_layout_spec.rb
|
100
102
|
- spec/grape_rabl_partials_spec.rb
|
101
103
|
- spec/grape_rabl_spec.rb
|
@@ -129,13 +131,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
131
|
- !ruby/object:Gem::Version
|
130
132
|
version: '0'
|
131
133
|
requirements: []
|
132
|
-
|
133
|
-
rubygems_version: 2.6.12
|
134
|
+
rubygems_version: 3.0.3
|
134
135
|
signing_key:
|
135
136
|
specification_version: 4
|
136
137
|
summary: Use rabl in grape
|
137
138
|
test_files:
|
138
139
|
- spec/grape_rabl_configuration.rb
|
140
|
+
- spec/grape_rabl_formatter_spec.rb
|
139
141
|
- spec/grape_rabl_layout_spec.rb
|
140
142
|
- spec/grape_rabl_partials_spec.rb
|
141
143
|
- spec/grape_rabl_spec.rb
|