grape-roar 0.1.0 → 0.2.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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -24
- data/.rubocop_todo.yml +20 -0
- data/.travis.yml +3 -1
- data/CHANGELOG.md +6 -1
- data/Gemfile +4 -4
- data/README.md +55 -5
- data/lib/grape/roar.rb +1 -0
- data/lib/grape/roar/decorator.rb +11 -0
- data/lib/grape/roar/formatter.rb +1 -2
- data/lib/grape/roar/version.rb +1 -1
- data/spec/decorator_spec.rb +29 -0
- data/spec/support/user.rb +9 -0
- data/spec/support/user_representer.rb +11 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d20b4c91d2e6c8ddf666534169e08e979d1f0b4
|
4
|
+
data.tar.gz: 80f25794c1901dc9dcbeb5d137dfef37ab634121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 268ee883eafd778ae6fdaf2a68392426f152532d8354e75e5620c33b869f115a4a4fe5382ad222b70720e95eedf05e612fdebdb12d23542af8942685a393acbf
|
7
|
+
data.tar.gz: f9c92f7d2a629d6d23937ac1b7017530d467e74bf53be5ab2651b6d3c7991d59fb5c31be6204f95d04b3df4057a65e4f7cd8f3b54d427cb90c9b0375c3af6c88
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -3,27 +3,4 @@ AllCops:
|
|
3
3
|
- vendor/**/*
|
4
4
|
- bin/**/*
|
5
5
|
|
6
|
-
|
7
|
-
Enabled: false
|
8
|
-
|
9
|
-
MethodLength:
|
10
|
-
Enabled: false
|
11
|
-
|
12
|
-
ClassLength:
|
13
|
-
Enabled: false
|
14
|
-
|
15
|
-
Documentation:
|
16
|
-
# don't require classes to be documented
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
CollectionMethods:
|
20
|
-
# don't prefer map to collect, recuce to inject
|
21
|
-
Enabled: false
|
22
|
-
|
23
|
-
Encoding:
|
24
|
-
# no need to always specify encoding
|
25
|
-
Enabled: false
|
26
|
-
|
27
|
-
FileName:
|
28
|
-
# allow grape-roar.rb
|
29
|
-
Enabled: false
|
6
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-12-18 10:52:56 -0500 using RuboCop version 0.28.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 8
|
9
|
+
# Configuration parameters: AllowURI, URISchemes.
|
10
|
+
Metrics/LineLength:
|
11
|
+
Max: 304
|
12
|
+
|
13
|
+
# Offense count: 13
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Configuration parameters: Exclude.
|
19
|
+
Style/FileName:
|
20
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0 (12/18/2014)
|
2
2
|
------------------
|
3
3
|
|
4
|
+
* [#10](https://github.com/dblock/grape-roar/pull/10): Support for Roar decorator - [@sdbondi](https://github.com/sdbondi).
|
5
|
+
|
6
|
+
0.1.0 (7/17/2014)
|
7
|
+
-----------------
|
8
|
+
|
4
9
|
* Initial public release, with support for Grape `present` - [@dblock](https://github.com/dblock).
|
data/Gemfile
CHANGED
@@ -3,14 +3,14 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development do
|
6
|
-
gem
|
6
|
+
gem 'rake'
|
7
7
|
end
|
8
8
|
|
9
9
|
group :test do
|
10
|
-
gem
|
11
|
-
gem
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
|
+
gem 'rack-test'
|
12
12
|
end
|
13
13
|
|
14
14
|
group :development, :test do
|
15
|
-
gem 'rubocop', '0.
|
15
|
+
gem 'rubocop', '0.28.0'
|
16
16
|
end
|
data/README.md
CHANGED
@@ -5,6 +5,11 @@ Use [Roar](https://github.com/apotonick/roar) with [Grape](https://github.com/in
|
|
5
5
|
|
6
6
|
[](http://travis-ci.org/dblock/grape-roar)
|
7
7
|
|
8
|
+
Demo
|
9
|
+
----
|
10
|
+
|
11
|
+
The [grape-with-roar](https://github.com/dblock/grape-with-roar) project deployed [here on heroku](http://grape-with-roar.herokuapp.com).
|
12
|
+
|
8
13
|
Installation
|
9
14
|
------------
|
10
15
|
|
@@ -30,7 +35,7 @@ end
|
|
30
35
|
|
31
36
|
### Use Grape's Present
|
32
37
|
|
33
|
-
You can use Grape's `present` keyword after including Grape::Roar::
|
38
|
+
You can use Grape's `present` keyword after including Grape::Roar::Representer into a representer module.
|
34
39
|
|
35
40
|
```ruby
|
36
41
|
module ProductRepresenter
|
@@ -49,9 +54,27 @@ get 'product/:id' do
|
|
49
54
|
end
|
50
55
|
```
|
51
56
|
|
52
|
-
|
57
|
+
Presenting collections works the same way. The following example returns an embedded set of products in the HAL Hypermedia format.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
module ProductsRepresenter
|
61
|
+
include Roar::Representer::JSON::HAL
|
62
|
+
include Roar::Representer::Feature::Hypermedia
|
63
|
+
include Grape::Roar::Representer
|
64
|
+
|
65
|
+
collection :entries, extend: ProductPresenter, as: :products, embedded: true
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
get 'products' do
|
71
|
+
present Product.all, with: ProductsRepresenter
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
### Accessing the Request Inside a Representer
|
53
76
|
|
54
|
-
The formatter invokes `to_json` on presented objects and provides access to the requesting environment via the `env` option. The following example renders a full request URL in a
|
77
|
+
The formatter invokes `to_json` on presented objects and provides access to the requesting environment via the `env` option. The following example renders a full request URL in a representer.
|
55
78
|
|
56
79
|
```ruby
|
57
80
|
module ProductRepresenter
|
@@ -66,6 +89,33 @@ module ProductRepresenter
|
|
66
89
|
end
|
67
90
|
```
|
68
91
|
|
92
|
+
### Decorators
|
93
|
+
|
94
|
+
If you prefer to use a decorator class instead of modules.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
class ProductRepresenter < Grape::Roar::Decorator
|
98
|
+
include Roar::Representer::JSON
|
99
|
+
include Roar::Representer::Feature::Hypermedia
|
100
|
+
|
101
|
+
link :self do |opts|
|
102
|
+
"#{request(opts).url}/#{represented.id}"
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def request(opts)
|
108
|
+
Grape::Request.new(opts[:env])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
get 'products' do
|
115
|
+
present Product.all, with: ProductsRepresenter
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
69
119
|
Contributing
|
70
120
|
------------
|
71
121
|
|
@@ -74,6 +124,6 @@ See [CONTRIBUTING](CONTRIBUTING.md).
|
|
74
124
|
Copyright and License
|
75
125
|
---------------------
|
76
126
|
|
77
|
-
MIT License, see [LICENSE](
|
127
|
+
MIT License, see [LICENSE](LICENSE) for details.
|
78
128
|
|
79
|
-
(c) 2012-2014 [Daniel Doubrovkine](
|
129
|
+
(c) 2012-2014 [Daniel Doubrovkine](https://github.com/dblock) & Contributors, [Artsy](https://artsy.net)
|
data/lib/grape/roar.rb
CHANGED
data/lib/grape/roar/formatter.rb
CHANGED
data/lib/grape/roar/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Grape::Roar::Decorator do
|
4
|
+
subject do
|
5
|
+
Class.new(Grape::API)
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
subject.format :json
|
10
|
+
subject.formatter :json, Grape::Formatter::Roar
|
11
|
+
end
|
12
|
+
|
13
|
+
def app
|
14
|
+
subject
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'decorator' do
|
18
|
+
before do
|
19
|
+
subject.get('/user/:id') do
|
20
|
+
present User.new(name: 'Lonestar', id: params[:id]), with: UserRepresenter
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns a hypermedia representation' do
|
25
|
+
get '/user/666'
|
26
|
+
expect(last_response.body).to eq '{"name":"Lonestar","id":"666","links":[{"rel":"self","href":"/user/666"}]}'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-roar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- .gitignore
|
49
49
|
- .rspec
|
50
50
|
- .rubocop.yml
|
51
|
+
- .rubocop_todo.yml
|
51
52
|
- .travis.yml
|
52
53
|
- CHANGELOG.md
|
53
54
|
- CONTRIBUTING.md
|
@@ -58,9 +59,11 @@ files:
|
|
58
59
|
- grape-roar.gemspec
|
59
60
|
- lib/grape-roar.rb
|
60
61
|
- lib/grape/roar.rb
|
62
|
+
- lib/grape/roar/decorator.rb
|
61
63
|
- lib/grape/roar/formatter.rb
|
62
64
|
- lib/grape/roar/representer.rb
|
63
65
|
- lib/grape/roar/version.rb
|
66
|
+
- spec/decorator_spec.rb
|
64
67
|
- spec/nested_representer_spec.rb
|
65
68
|
- spec/present_with_spec.rb
|
66
69
|
- spec/representer_spec.rb
|
@@ -71,6 +74,8 @@ files:
|
|
71
74
|
- spec/support/order_representer.rb
|
72
75
|
- spec/support/product.rb
|
73
76
|
- spec/support/product_representer.rb
|
77
|
+
- spec/support/user.rb
|
78
|
+
- spec/support/user_representer.rb
|
74
79
|
homepage: http://github.com/dblock/grape-roar
|
75
80
|
licenses: []
|
76
81
|
metadata: {}
|
@@ -90,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
95
|
version: '0'
|
91
96
|
requirements: []
|
92
97
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.1.11
|
94
99
|
signing_key:
|
95
100
|
specification_version: 4
|
96
101
|
summary: Enable Resource-Oriented Architectures in Grape API DSL
|