Skip to content

Commit fe032b4

Browse files
committed
Added role to user attributes serialization;
1 parent 6905891 commit fe032b4

File tree

3 files changed

+48
-43
lines changed

3 files changed

+48
-43
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gem 'bcrypt', '~> 3.1.7'
1717
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
1818
gem 'rack-cors'
1919
# Serialization
20-
gem 'active_model_serializers', '~> 0.10.5'
20+
gem 'active_model_serializers', '~> 0.10.6'
2121
# Authentication
2222
gem 'devise'
2323
gem 'jwt'

Gemfile.lock

+42-41
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
actioncable (5.1.0.rc1)
5-
actionpack (= 5.1.0.rc1)
4+
actioncable (5.1.0.rc2)
5+
actionpack (= 5.1.0.rc2)
66
nio4r (~> 2.0)
77
websocket-driver (~> 0.6.1)
8-
actionmailer (5.1.0.rc1)
9-
actionpack (= 5.1.0.rc1)
10-
actionview (= 5.1.0.rc1)
11-
activejob (= 5.1.0.rc1)
8+
actionmailer (5.1.0.rc2)
9+
actionpack (= 5.1.0.rc2)
10+
actionview (= 5.1.0.rc2)
11+
activejob (= 5.1.0.rc2)
1212
mail (~> 2.5, >= 2.5.4)
1313
rails-dom-testing (~> 2.0)
14-
actionpack (5.1.0.rc1)
15-
actionview (= 5.1.0.rc1)
16-
activesupport (= 5.1.0.rc1)
14+
actionpack (5.1.0.rc2)
15+
actionview (= 5.1.0.rc2)
16+
activesupport (= 5.1.0.rc2)
1717
rack (~> 2.0)
1818
rack-test (~> 0.6.3)
1919
rails-dom-testing (~> 2.0)
2020
rails-html-sanitizer (~> 1.0, >= 1.0.2)
21-
actionview (5.1.0.rc1)
22-
activesupport (= 5.1.0.rc1)
21+
actionview (5.1.0.rc2)
22+
activesupport (= 5.1.0.rc2)
2323
builder (~> 3.1)
2424
erubi (~> 1.4)
2525
rails-dom-testing (~> 2.0)
2626
rails-html-sanitizer (~> 1.0, >= 1.0.3)
27-
active_model_serializers (0.10.5)
27+
active_model_serializers (0.10.6)
2828
actionpack (>= 4.1, < 6)
2929
activemodel (>= 4.1, < 6)
3030
case_transform (>= 0.2)
3131
jsonapi-renderer (>= 0.1.1.beta1, < 0.2)
32-
activejob (5.1.0.rc1)
33-
activesupport (= 5.1.0.rc1)
32+
activejob (5.1.0.rc2)
33+
activesupport (= 5.1.0.rc2)
3434
globalid (>= 0.3.6)
35-
activemodel (5.1.0.rc1)
36-
activesupport (= 5.1.0.rc1)
37-
activerecord (5.1.0.rc1)
38-
activemodel (= 5.1.0.rc1)
39-
activesupport (= 5.1.0.rc1)
35+
activemodel (5.1.0.rc2)
36+
activesupport (= 5.1.0.rc2)
37+
activerecord (5.1.0.rc2)
38+
activemodel (= 5.1.0.rc2)
39+
activesupport (= 5.1.0.rc2)
4040
arel (~> 8.0)
41-
activesupport (5.1.0.rc1)
41+
activesupport (5.1.0.rc2)
4242
concurrent-ruby (~> 1.0, >= 1.0.2)
4343
i18n (~> 0.7)
4444
minitest (~> 5.1)
@@ -67,7 +67,7 @@ GEM
6767
docile (1.1.5)
6868
dry-auto_inject (0.4.2)
6969
dry-container (>= 0.3.4)
70-
dry-configurable (0.6.2)
70+
dry-configurable (0.7.0)
7171
concurrent-ruby (~> 1.0)
7272
dry-container (0.6.0)
7373
concurrent-ruby (~> 1.0)
@@ -83,9 +83,9 @@ GEM
8383
ffi (1.9.18)
8484
globalid (0.4.0)
8585
activesupport (>= 4.2.0)
86-
has_scope (0.7.0)
87-
actionpack (>= 4.1, < 5.1)
88-
activesupport (>= 4.1, < 5.1)
86+
has_scope (0.7.1)
87+
actionpack (>= 4.1, < 5.2)
88+
activesupport (>= 4.1, < 5.2)
8989
i18n (0.8.1)
9090
json (2.1.0)
9191
jsonapi-renderer (0.1.2)
@@ -108,7 +108,7 @@ GEM
108108
ruby_dep (~> 1.2)
109109
loofah (2.0.3)
110110
nokogiri (>= 1.5.9)
111-
mail (2.6.4)
111+
mail (2.6.5)
112112
mime-types (>= 1.16, < 4)
113113
method_source (0.8.2)
114114
mime-types (3.1)
@@ -133,35 +133,36 @@ GEM
133133
rack-cors (0.4.1)
134134
rack-test (0.6.3)
135135
rack (>= 1.0)
136-
rails (5.1.0.rc1)
137-
actioncable (= 5.1.0.rc1)
138-
actionmailer (= 5.1.0.rc1)
139-
actionpack (= 5.1.0.rc1)
140-
actionview (= 5.1.0.rc1)
141-
activejob (= 5.1.0.rc1)
142-
activemodel (= 5.1.0.rc1)
143-
activerecord (= 5.1.0.rc1)
144-
activesupport (= 5.1.0.rc1)
136+
rails (5.1.0.rc2)
137+
actioncable (= 5.1.0.rc2)
138+
actionmailer (= 5.1.0.rc2)
139+
actionpack (= 5.1.0.rc2)
140+
actionview (= 5.1.0.rc2)
141+
activejob (= 5.1.0.rc2)
142+
activemodel (= 5.1.0.rc2)
143+
activerecord (= 5.1.0.rc2)
144+
activesupport (= 5.1.0.rc2)
145145
bundler (>= 1.3.0, < 2.0)
146-
railties (= 5.1.0.rc1)
146+
railties (= 5.1.0.rc2)
147147
sprockets-rails (>= 2.0.0)
148148
rails-dom-testing (2.0.2)
149149
activesupport (>= 4.2.0, < 6.0)
150150
nokogiri (~> 1.6)
151151
rails-html-sanitizer (1.0.3)
152152
loofah (~> 2.0)
153-
railties (5.1.0.rc1)
154-
actionpack (= 5.1.0.rc1)
155-
activesupport (= 5.1.0.rc1)
153+
railties (5.1.0.rc2)
154+
actionpack (= 5.1.0.rc2)
155+
activesupport (= 5.1.0.rc2)
156156
method_source
157157
rake (>= 0.8.7)
158158
thor (>= 0.18.1, < 2.0)
159159
rake (12.0.0)
160160
rb-fsevent (0.9.8)
161161
rb-inotify (0.9.8)
162162
ffi (>= 0.5.0)
163-
responders (2.3.0)
164-
railties (>= 4.2.0, < 5.1)
163+
responders (2.4.0)
164+
actionpack (>= 4.2.0, < 5.3)
165+
railties (>= 4.2.0, < 5.3)
165166
rspec-core (3.5.4)
166167
rspec-support (~> 3.5.0)
167168
rspec-expectations (3.5.0)
@@ -218,7 +219,7 @@ PLATFORMS
218219
ruby
219220

220221
DEPENDENCIES
221-
active_model_serializers (~> 0.10.5)
222+
active_model_serializers (~> 0.10.6)
222223
api-pagination
223224
bcrypt (~> 3.1.7)
224225
byebug

app/serializers/user_serializer.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
class UserSerializer < ActiveModel::Serializer
2-
attributes :id, :name, :email, :confirmed_at, :created_at, :updated_at
2+
attributes :id, :name, :email, :confirmed_at, :created_at, :updated_at, :role
33
belongs_to :customer, serializer: CustomerSerializer
44
belongs_to :role, serializer: RoleSerializer
55

6+
def role
7+
RoleSerializer.new(object.role)
8+
end
9+
610
link :self do
711
href user_path(object)
812
end

0 commit comments

Comments
 (0)