grape-active_model_serializers 1.2.1 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +0 -4
- data/README.md +17 -3
- data/grape-active_model_serializers.gemspec +2 -3
- data/lib/.travis.yml +3 -1
- data/lib/grape-active_model_serializers/formatter.rb +2 -6
- data/lib/grape-active_model_serializers/version.rb +1 -1
- data/spec/features/grape-active_model_serializers/render_spec.rb +0 -3
- data/spec/grape-active_model_serializers/endpoint_extension_spec.rb +7 -7
- data/spec/grape-active_model_serializers/formatter_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -2
- metadata +20 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d1fc34293532a51eb2a8694d46c26d874b56d3c
|
4
|
+
data.tar.gz: dd6d159497a55ee86f431402f02e0991cfae55c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1012cd5e379a6dd9b988cb23d02d84bc12e6c95a4a2b61390762f7f8bccab6cf4c55254bee506bb8d59a8ca82ab581e30c411a2bfdf09a6e78c979660007c06a
|
7
|
+
data.tar.gz: 4b9d9dbbd00137e3ed063ccc357efd36aeaabe6a446c2960022c951417cd2abf0b2bd1b175283da38af0bc67f568792b2e589edbbb5b999ff7898fd6282fe5c6
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -82,18 +82,18 @@ end
|
|
82
82
|
|
83
83
|
```ruby
|
84
84
|
# Serializer options can be specified on routes or namespaces.
|
85
|
-
namespace 'foo', :serializer =>
|
85
|
+
namespace 'foo', :serializer => BarSerializer do
|
86
86
|
get "/" do
|
87
87
|
# will use "bar" serializer
|
88
88
|
end
|
89
89
|
|
90
90
|
# Options specified on a route or namespace override those of the containing namespace.
|
91
|
-
get "/home", :serializer =>
|
91
|
+
get "/home", :serializer => HomeSerializer do
|
92
92
|
# will use "home" serializer
|
93
93
|
end
|
94
94
|
|
95
95
|
# All standard options for `ActiveModel::Serializers` are supported.
|
96
|
-
get "/fancy_homes", :root => 'world', :each_serializer =>
|
96
|
+
get "/fancy_homes", :root => 'world', :each_serializer => FancyHomesSerializer
|
97
97
|
...
|
98
98
|
end
|
99
99
|
end
|
@@ -109,6 +109,16 @@ get "/homes"
|
|
109
109
|
end
|
110
110
|
```
|
111
111
|
|
112
|
+
### Support for `default_serializer_options`
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
helper do
|
116
|
+
def default_serializer_options
|
117
|
+
{only: params[:only], except: params[:except]}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
112
122
|
### current_user
|
113
123
|
|
114
124
|
One of the nice features of ActiveModel::Serializers is that it
|
@@ -170,6 +180,10 @@ Enjoy :)
|
|
170
180
|
|
171
181
|
## Changelog
|
172
182
|
|
183
|
+
#### v1.2.1
|
184
|
+
* Adds support for active model serializer 0.9.x
|
185
|
+
|
186
|
+
|
173
187
|
#### v1.0.0
|
174
188
|
* Released on rubygems.org
|
175
189
|
* *BREAKING* Changes behaviour of root keys when serialising arrays. See [Array roots](https://github.com/jrhe/grape-active_model_serializers#array-roots)
|
@@ -17,11 +17,10 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.licenses = ['MIT']
|
18
18
|
|
19
19
|
gem.add_dependency "grape", "~> 0.3"
|
20
|
-
gem.add_dependency "active_model_serializers", ">= 0.9.0
|
20
|
+
gem.add_dependency "active_model_serializers", ">= 0.9.0"
|
21
21
|
|
22
22
|
gem.add_development_dependency "rspec"
|
23
23
|
gem.add_development_dependency "rack-test"
|
24
24
|
gem.add_development_dependency "rake"
|
25
|
-
gem.add_development_dependency "
|
26
|
-
gem.add_development_dependency 'guard-rspec'
|
25
|
+
gem.add_development_dependency "guard-rspec"
|
27
26
|
end
|
data/lib/.travis.yml
CHANGED
@@ -17,7 +17,7 @@ module Grape
|
|
17
17
|
options = build_options_from_endpoint(endpoint)
|
18
18
|
|
19
19
|
if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource))
|
20
|
-
options[:scope] =
|
20
|
+
options[:scope] = endpoint unless options.has_key?(:scope)
|
21
21
|
# ensure we have an root to fallback on
|
22
22
|
options[:resource_name] = default_root(endpoint) if resource.respond_to?(:to_ary)
|
23
23
|
serializer.new(resource, options.merge(other_options))
|
@@ -56,7 +56,7 @@ module Grape
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def build_options_from_endpoint(endpoint)
|
59
|
-
endpoint.namespace_options
|
59
|
+
[endpoint.default_serializer_options || {}, endpoint.namespace_options, endpoint.route_options].reduce(:merge)
|
60
60
|
end
|
61
61
|
|
62
62
|
# array root is the innermost namespace name ('space') if there is one,
|
@@ -70,10 +70,6 @@ module Grape
|
|
70
70
|
endpoint.options[:path][0].to_s.split('/')[-1]
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
74
|
-
def serialization_scope
|
75
|
-
:current_user
|
76
|
-
end
|
77
73
|
end
|
78
74
|
end
|
79
75
|
end
|
@@ -2,17 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Grape::EndpointExtension' do
|
4
4
|
|
5
|
-
subject { Grape::Endpoint.new(
|
5
|
+
subject { Grape::Endpoint.new({}, {path: '/', method: 'foo'}) }
|
6
6
|
|
7
7
|
let(:serializer) { Grape::Formatter::ActiveModelSerializers }
|
8
8
|
|
9
9
|
let(:user) do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
Object.new do
|
11
|
+
def name
|
12
|
+
'sven'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
16
|
|
17
17
|
let(:users) { [user, user] }
|
18
18
|
|
@@ -31,4 +31,33 @@ describe Grape::Formatter::ActiveModelSerializers do
|
|
31
31
|
expect(subject.meta_key).to eq({ meta_key: :custom_key_name })
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
describe '.fetch_serializer' do
|
36
|
+
let(:user) { User.new(first_name: 'John') }
|
37
|
+
let(:endpoint) { Grape::Endpoint.new({}, {path: '/', method: 'foo'}) }
|
38
|
+
let(:env) { { 'api.endpoint' => endpoint } }
|
39
|
+
|
40
|
+
before do
|
41
|
+
def endpoint.current_user
|
42
|
+
@current_user ||= User.new(first_name: 'Current user')
|
43
|
+
end
|
44
|
+
|
45
|
+
def endpoint.default_serializer_options
|
46
|
+
{ only: :only, except: :except }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
subject { described_class.fetch_serializer(user, env) }
|
51
|
+
|
52
|
+
it { should be_a UserSerializer }
|
53
|
+
|
54
|
+
it 'should have correct scope set' do
|
55
|
+
expect(subject.scope.current_user).to eq(endpoint.current_user)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should read default serializer options' do
|
59
|
+
expect(subject.instance_variable_get('@only')).to eq([:only])
|
60
|
+
expect(subject.instance_variable_get('@except')).to eq([:except])
|
61
|
+
end
|
62
|
+
end
|
34
63
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,8 +9,7 @@ require 'active_support/core_ext/hash/conversions'
|
|
9
9
|
require "active_support/json"
|
10
10
|
require 'rspec'
|
11
11
|
require 'rack/test'
|
12
|
-
|
13
|
-
require 'jazz_hands'
|
12
|
+
require 'grape-active_model_serializers'
|
14
13
|
|
15
14
|
RSpec.configure do |config|
|
16
15
|
config.include Rack::Test::Methods
|
metadata
CHANGED
@@ -1,111 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-active_model_serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Richard Henry Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: active_model_serializers
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9.0
|
33
|
+
version: 0.9.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.9.0
|
40
|
+
version: 0.9.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack-test
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: jazz_hands
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
80
|
+
- - '>='
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: guard-rspec
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- -
|
87
|
+
- - '>='
|
102
88
|
- !ruby/object:Gem::Version
|
103
89
|
version: '0'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- -
|
94
|
+
- - '>='
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0'
|
111
97
|
description: Provides a Formatter for the Grape API DSL to emit objects serialized
|
@@ -116,7 +102,7 @@ executables: []
|
|
116
102
|
extensions: []
|
117
103
|
extra_rdoc_files: []
|
118
104
|
files:
|
119
|
-
-
|
105
|
+
- .gitignore
|
120
106
|
- Gemfile
|
121
107
|
- Guardfile
|
122
108
|
- LICENSE.txt
|
@@ -149,17 +135,17 @@ require_paths:
|
|
149
135
|
- lib
|
150
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
137
|
requirements:
|
152
|
-
- -
|
138
|
+
- - '>='
|
153
139
|
- !ruby/object:Gem::Version
|
154
140
|
version: '0'
|
155
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
142
|
requirements:
|
157
|
-
- -
|
143
|
+
- - '>='
|
158
144
|
- !ruby/object:Gem::Version
|
159
145
|
version: '0'
|
160
146
|
requirements: []
|
161
147
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.0.14
|
163
149
|
signing_key:
|
164
150
|
specification_version: 4
|
165
151
|
summary: Use active_model_serializer in grape
|
@@ -174,4 +160,3 @@ test_files:
|
|
174
160
|
- spec/support/models/user.rb
|
175
161
|
- spec/support/serializers/blog_post_serializer.rb
|
176
162
|
- spec/support/serializers/user_serializer.rb
|
177
|
-
has_rdoc:
|