grape-active_model_serializers 1.0.1 → 1.1.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 708565b2aa28cddacf0cbd47a4f3f322480c832b
|
4
|
+
data.tar.gz: 82d88038489301fccf2e29da99a07af6c766f852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b17ce1b5d1bbd0462fedafa695f7bc0e5bdd97c776d9f948c43593f96aef3cf26f050604aca07e8a741a02c58830bca1454a45b8609a9a332dcb14f8fe75f010
|
7
|
+
data.tar.gz: 7497abba7aceba227dd9b3c87f1b975d253dda9715c1301533dd2f9d7e610ba8f1dd1e8476ecacdacd4cdfb9e165e72e5f3dc8e6dea76c210f6f47a0bc4e8110
|
data/README.md
CHANGED
@@ -4,6 +4,10 @@ Use [active_model_serializers](https://github.com/rails-api/active_model_seriali
|
|
4
4
|
|
5
5
|
[![Build Status](https://api.travis-ci.org/jrhe/grape-active_model_serializers.png)](http://travis-ci.org/jrhe/grape-active_model_serializers) [![Dependency Status](https://gemnasium.com/jrhe/grape-active_model_serializers.png)](https://gemnasium.com/jrhe/grape-active_model_serializers) [![Code Climate](https://codeclimate.com/github/jrhe/grape-active_model_serializers.png)](https://codeclimate.com/github/jrhe/grape-active_model_serializers)
|
6
6
|
|
7
|
+
## Breaking Changes
|
8
|
+
#### v1.0.0
|
9
|
+
* *BREAKING* Changes behaviour of root keys when serialising arrays. See [Array roots](https://github.com/jrhe/grape-active_model_serializers#array-roots)
|
10
|
+
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
Add the `grape` and `grape-active_model_serializers` gems to Gemfile.
|
@@ -23,7 +27,7 @@ And then execute:
|
|
23
27
|
|
24
28
|
```ruby
|
25
29
|
# config.ru
|
26
|
-
require 'grape
|
30
|
+
require 'grape-active_model_serializers'
|
27
31
|
```
|
28
32
|
|
29
33
|
|
@@ -56,7 +60,7 @@ end
|
|
56
60
|
In this case, as User objects are being returned, grape-active_model_serializers will look for a serializer named UserSerializer.
|
57
61
|
|
58
62
|
### Array roots
|
59
|
-
When serializing an array, the array root is set to the innermost namespace name if there is one, otherwise it is set to the route name (e.g. get 'name')
|
63
|
+
When serializing an array, the array root is set to the innermost namespace name if there is one, otherwise it is set to the route name (e.g. get 'name').
|
60
64
|
|
61
65
|
```ruby
|
62
66
|
namespace :users do
|
@@ -95,6 +99,37 @@ namespace 'foo', :serializer => :bar do
|
|
95
99
|
end
|
96
100
|
```
|
97
101
|
|
102
|
+
### current_user
|
103
|
+
|
104
|
+
One of the nice features of ActiveModel::Serializers is that it
|
105
|
+
provides access to the authorization context via the `current_user`.
|
106
|
+
|
107
|
+
In Grape, you can get the same behavior by defining a `current_user`
|
108
|
+
helper method:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
helpers do
|
112
|
+
def current_user
|
113
|
+
@current_user ||= User.where( :access_token => params[:token]).first
|
114
|
+
end
|
115
|
+
|
116
|
+
def authenticate!
|
117
|
+
error!('401 Unauthenticated', 401) unless current_user
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
Then, in your serializer, you could show or hide some elements
|
123
|
+
based on the current user's permissions:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
class PostSerializer < ActiveModel::Serializer
|
127
|
+
...
|
128
|
+
def include_admin_comments?
|
129
|
+
current_user.roles.member? :admin
|
130
|
+
end
|
131
|
+
end
|
132
|
+
```
|
98
133
|
|
99
134
|
### Full Example
|
100
135
|
|
@@ -123,6 +158,12 @@ See "Writing Tests" in https://github.com/intridea/grape.
|
|
123
158
|
|
124
159
|
Enjoy :)
|
125
160
|
|
161
|
+
## Changelog
|
162
|
+
|
163
|
+
#### v1.0.0
|
164
|
+
* Released on rubygems.org
|
165
|
+
* *BREAKING* Changes behaviour of root keys when serialising arrays. See [Array roots](https://github.com/jrhe/grape-active_model_serializers#array-roots)
|
166
|
+
|
126
167
|
|
127
168
|
## Contributing
|
128
169
|
|
@@ -16,9 +16,18 @@ module Grape
|
|
16
16
|
options[:route_options]
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.included(base)
|
20
|
+
mattr_accessor :_serialization_scope
|
21
|
+
self._serialization_scope = :current_user
|
22
|
+
|
23
|
+
base.class_eval do
|
24
|
+
def serialization_scope
|
25
|
+
send(_serialization_scope) if _serialization_scope && respond_to?(_serialization_scope, true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
19
30
|
def default_serializer_options; end
|
20
|
-
def serialization_scope; end
|
21
|
-
def _serialization_scope; end
|
22
31
|
def url_options; end
|
23
32
|
end
|
24
33
|
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-active_model_serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
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:
|
11
|
+
date: 2014-06-14 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
33
|
version: 0.8.1
|
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
40
|
version: 0.8.1
|
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
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: jazz_hands
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: guard-rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: Provides a Formatter for the Grape API DSL to emit objects serialized
|
@@ -116,8 +116,7 @@ executables: []
|
|
116
116
|
extensions: []
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
|
-
- .
|
120
|
-
- .gitignore
|
119
|
+
- ".gitignore"
|
121
120
|
- Gemfile
|
122
121
|
- Guardfile
|
123
122
|
- LICENSE.txt
|
@@ -130,7 +129,6 @@ files:
|
|
130
129
|
- lib/grape-active_model_serializers/endpoint_extension.rb
|
131
130
|
- lib/grape-active_model_serializers/formatter.rb
|
132
131
|
- lib/grape-active_model_serializers/version.rb
|
133
|
-
- spec/.DS_Store
|
134
132
|
- spec/grape-active_model_serializers/formatter_spec.rb
|
135
133
|
- spec/grape-active_model_serializers_spec.rb
|
136
134
|
- spec/old_grape_ams_spec.rb
|
@@ -149,17 +147,17 @@ require_paths:
|
|
149
147
|
- lib
|
150
148
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
149
|
requirements:
|
152
|
-
- -
|
150
|
+
- - ">="
|
153
151
|
- !ruby/object:Gem::Version
|
154
152
|
version: '0'
|
155
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
154
|
requirements:
|
157
|
-
- -
|
155
|
+
- - ">="
|
158
156
|
- !ruby/object:Gem::Version
|
159
157
|
version: '0'
|
160
158
|
requirements: []
|
161
159
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.0
|
160
|
+
rubygems_version: 2.2.0
|
163
161
|
signing_key:
|
164
162
|
specification_version: 4
|
165
163
|
summary: Use active_model_serializer in grape
|