mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Compare commits
147 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb0f9d088d | ||
|
|
15b7974fac | ||
|
|
be7f083d02 | ||
|
|
2cc2a048c6 | ||
|
|
26bba194d0 | ||
|
|
6fd5c66837 | ||
|
|
7ff2ac64b7 | ||
|
|
f815d3e9f8 | ||
|
|
3d0b5acc37 | ||
|
|
209834dc49 | ||
|
|
141feeb259 | ||
|
|
427dd05a73 | ||
|
|
192c86ab2a | ||
|
|
7dbb583873 | ||
|
|
bd53d9b213 | ||
|
|
b0039e3758 | ||
|
|
70604bbae7 | ||
|
|
7f751fc1f7 | ||
|
|
be5fbf3d54 | ||
|
|
22f2cb76dd | ||
|
|
a7915c80c2 | ||
|
|
96ab640eb9 | ||
|
|
c6c3927e00 | ||
|
|
9939d54289 | ||
|
|
a39794df5b | ||
|
|
89dcdace86 | ||
|
|
873cf4add2 | ||
|
|
17d0e6bdb7 | ||
|
|
b76aae7f8e | ||
|
|
f608aef83c | ||
|
|
bc4805cbc1 | ||
|
|
f1a2ec7f99 | ||
|
|
09264da273 | ||
|
|
238d7921ec | ||
|
|
b358271ef5 | ||
|
|
c7e847fc72 | ||
|
|
127b04ba33 | ||
|
|
cb67434b46 | ||
|
|
b7bf03c127 | ||
|
|
1b679d4c8c | ||
|
|
572f11b7e0 | ||
|
|
ca6c009273 | ||
|
|
0d3999c36d | ||
|
|
05e5ba6939 | ||
|
|
4b2b9ef730 | ||
|
|
01ecc5dea3 | ||
|
|
12724807e9 | ||
|
|
bcf21ea0a6 | ||
|
|
db4e5267fd | ||
|
|
eb865c276d | ||
|
|
506636abfb | ||
|
|
65313b901b | ||
|
|
2a8b9f4105 | ||
|
|
fce8be0dc0 | ||
|
|
f5f5d4db9e | ||
|
|
ed97e94e71 | ||
|
|
4f9d64096b | ||
|
|
3a200d7fe1 | ||
|
|
f3a19bd515 | ||
|
|
9c77bb6a60 | ||
|
|
76936e7bb9 | ||
|
|
4559774d60 | ||
|
|
993a48fdcf | ||
|
|
65cf4836c8 | ||
|
|
f3b202746b | ||
|
|
41f2e11c4d | ||
|
|
5fe473fe0d | ||
|
|
d274295ee5 | ||
|
|
a9ea81a831 | ||
|
|
ca531789c3 | ||
|
|
c41e243ed8 | ||
|
|
b41451c9bf | ||
|
|
3dd6cccb4d | ||
|
|
00a47d3da4 | ||
|
|
3c5e11bb0f | ||
|
|
33ec26fa12 | ||
|
|
0bbeeb384e | ||
|
|
196216b250 | ||
|
|
51f2643f40 | ||
|
|
9745a2f735 | ||
|
|
5916014b48 | ||
|
|
92dde58f5f | ||
|
|
82e90091fd | ||
|
|
b439fe69c6 | ||
|
|
e3480345e3 | ||
|
|
54d40c79e8 | ||
|
|
c6a14c9eac | ||
|
|
1fd324947f | ||
|
|
a0de45a4d8 | ||
|
|
cf29db34c6 | ||
|
|
0fcb8a6cce | ||
|
|
5e1e138d47 | ||
|
|
4076a480b7 | ||
|
|
88367da970 | ||
|
|
4d7c2457d7 | ||
|
|
715a702f55 | ||
|
|
4a995955ea | ||
|
|
ab517d1a2d | ||
|
|
1c9214d041 | ||
|
|
6a7d864605 | ||
|
|
c2fa01624d | ||
|
|
4f78319219 | ||
|
|
b1de431731 | ||
|
|
967ff8dcc0 | ||
|
|
1e4d117b99 | ||
|
|
402883d84f | ||
|
|
e4b3224c64 | ||
|
|
b7442e741c | ||
|
|
1539747a59 | ||
|
|
622872ae2b | ||
|
|
92e9a66e97 | ||
|
|
16e5204eab | ||
|
|
ff71ef26eb | ||
|
|
d8e983604b | ||
|
|
7387266c37 | ||
|
|
a89e78c655 | ||
|
|
a5ab62fd18 | ||
|
|
be7ee70376 | ||
|
|
b48aeeef1e | ||
|
|
01d4f0464b | ||
|
|
f353dedf28 | ||
|
|
db617b8bf9 | ||
|
|
9a2f4894ed | ||
|
|
4c6f104ae9 | ||
|
|
1570437795 | ||
|
|
ec1022ecb3 | ||
|
|
b5f886cb95 | ||
|
|
ec905d8179 | ||
|
|
c25f2f3863 | ||
|
|
4e6bd61350 | ||
|
|
d5babdd060 | ||
|
|
85dfef9072 | ||
|
|
59aed4d00e | ||
|
|
a5423dab20 | ||
|
|
9a2e1e4743 | ||
|
|
0dd7680fe5 | ||
|
|
21bcfd891d | ||
|
|
82db1301f6 | ||
|
|
23f03ffd30 | ||
|
|
97b587b14c | ||
|
|
adf110f4df | ||
|
|
2c0b15d22f | ||
|
|
dfa6caac27 | ||
|
|
49f2dca730 | ||
|
|
4054f43309 | ||
|
|
e036b71e0c | ||
|
|
6e11d6234e |
@ -59,6 +59,10 @@ Style/MissingElse:
|
|||||||
Style/EmptyElse:
|
Style/EmptyElse:
|
||||||
EnforcedStyle: empty
|
EnforcedStyle: empty
|
||||||
|
|
||||||
|
Style/FrozenStringLiteralComment:
|
||||||
|
Enabled: true
|
||||||
|
EnforcedStyle: always
|
||||||
|
|
||||||
Style/MultilineOperationIndentation:
|
Style/MultilineOperationIndentation:
|
||||||
EnforcedStyle: indented
|
EnforcedStyle: indented
|
||||||
|
|
||||||
|
|||||||
70
.travis.yml
70
.travis.yml
@ -1,55 +1,63 @@
|
|||||||
language: ruby
|
language: ruby
|
||||||
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
rvm:
|
|
||||||
- 2.1
|
|
||||||
- 2.2.6
|
|
||||||
- 2.3.3
|
|
||||||
- ruby-head
|
|
||||||
- jruby-9.1.5.0 # is precompiled per http://rubies.travis-ci.org/
|
|
||||||
- jruby-head
|
|
||||||
|
|
||||||
jdk:
|
|
||||||
- oraclejdk8
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- gem update --system
|
|
||||||
- rvm @global do gem uninstall bundler -a -x
|
|
||||||
- rvm @global do gem install bundler -v 1.13.7
|
|
||||||
install: bundle install --path=vendor/bundle --retry=3 --jobs=3
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- vendor/bundle
|
- vendor/bundle
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- "travis_retry gem update --system 2.7.8"
|
||||||
|
- "travis_retry gem install bundler -v '1.17.3'"
|
||||||
|
install: BUNDLER_VERSION=1.17.3 bundle install --path=vendor/bundle --retry=3 --jobs=3
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- bundle exec rake ci
|
- bundle exec rake ci
|
||||||
after_success:
|
after_success:
|
||||||
- codeclimate-test-reporter
|
- codeclimate-test-reporter
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
|
||||||
- "JRUBY_OPTS='--dev -J-Xmx1024M --debug'"
|
|
||||||
matrix:
|
matrix:
|
||||||
- "RAILS_VERSION=4.1"
|
- "RAILS_VERSION=4.1"
|
||||||
- "RAILS_VERSION=4.2"
|
- "RAILS_VERSION=4.2"
|
||||||
- "RAILS_VERSION=5.0"
|
- "RAILS_VERSION=5.0"
|
||||||
|
- "RAILS_VERSION=5.1"
|
||||||
|
- "RAILS_VERSION=5.2"
|
||||||
- "RAILS_VERSION=master"
|
- "RAILS_VERSION=master"
|
||||||
|
|
||||||
|
rvm:
|
||||||
|
- 2.1.10
|
||||||
|
- 2.2.8
|
||||||
|
- 2.3.5
|
||||||
|
- 2.4.2
|
||||||
|
- 2.5.3
|
||||||
|
- ruby-head
|
||||||
|
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- 0-10-stable
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
|
include:
|
||||||
|
- { rvm: jruby-9.1.13.0, jdk: oraclejdk8, env: "RAILS_VERSION=4.1 JRUBY_OPTS='--dev -J-Xmx1024M --debug'" }
|
||||||
|
- { rvm: jruby-9.1.13.0, jdk: oraclejdk8, env: "RAILS_VERSION=4.2 JRUBY_OPTS='--dev -J-Xmx1024M --debug'" }
|
||||||
|
- { rvm: jruby-9.1.13.0, jdk: oraclejdk8, env: "RAILS_VERSION=5.1 JRUBY_OPTS='--dev -J-Xmx1024M --debug'" }
|
||||||
|
# See JRuby currently failing on Rails 5+ https://github.com/jruby/activerecord-jdbc-adapter/issues/708
|
||||||
|
# - { rvm: jruby-9.1.13.0, jdk: oraclejdk8, env: "RAILS_VERSION=5.0 JRUBY_OPTS='--dev -J-Xmx1024M --debug'" }
|
||||||
|
# - { rvm: jruby-head, jdk: oraclejdk8, env: "RAILS_VERSION=5.1 JRUBY_OPTS='--dev -J-Xmx1024M --debug'" }
|
||||||
exclude:
|
exclude:
|
||||||
- rvm: 2.1
|
- { rvm: 2.1.10, env: RAILS_VERSION=master }
|
||||||
env: RAILS_VERSION=master
|
- { rvm: 2.2.8, env: RAILS_VERSION=master }
|
||||||
- rvm: jruby-9.1.5.0
|
- { rvm: 2.3.5, env: RAILS_VERSION=master }
|
||||||
env: RAILS_VERSION=master
|
- { rvm: 2.4.2, env: RAILS_VERSION=master }
|
||||||
- rvm: jruby-head
|
- { rvm: 2.1.10, env: RAILS_VERSION=5.0 }
|
||||||
env: RAILS_VERSION=master
|
- { rvm: 2.1.10, env: RAILS_VERSION=5.1 }
|
||||||
- rvm: 2.1
|
- { rvm: 2.1.10, env: RAILS_VERSION=5.2 }
|
||||||
env: RAILS_VERSION=5.0
|
- { rvm: 2.4.2, env: RAILS_VERSION=4.1 }
|
||||||
- rvm: jruby-9.1.5.0
|
- { rvm: 2.5.3, env: RAILS_VERSION=4.1 }
|
||||||
env: RAILS_VERSION=5.0
|
- { rvm: ruby-head, env: RAILS_VERSION=4.1 }
|
||||||
- rvm: jruby-head
|
|
||||||
env: RAILS_VERSION=5.0
|
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- rvm: ruby-head
|
- rvm: ruby-head
|
||||||
- rvm: jruby-head
|
- rvm: jruby-head
|
||||||
|
# See JRuby currently failing on Rails 5+ https://github.com/jruby/activerecord-jdbc-adapter/issues/708
|
||||||
|
- { rvm: jruby-9.1.13.0, jdk: oraclejdk8, env: "RAILS_VERSION=5.1 JRUBY_OPTS='--dev -J-Xmx1024M --debug'" }
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|||||||
76
CHANGELOG.md
76
CHANGELOG.md
@ -1,6 +1,6 @@
|
|||||||
## 0.10.x
|
## 0.10.x
|
||||||
|
|
||||||
### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.6...master)
|
### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.9...0-10-stable)
|
||||||
|
|
||||||
Breaking changes:
|
Breaking changes:
|
||||||
|
|
||||||
@ -10,6 +10,80 @@ Fixes:
|
|||||||
|
|
||||||
Misc:
|
Misc:
|
||||||
|
|
||||||
|
### [v0.10.9 (2019-02-08)](https://github.com/rails-api/active_model_serializers/compare/v0.10.8...v0.10.9)
|
||||||
|
|
||||||
|
|
||||||
|
Fixes:
|
||||||
|
|
||||||
|
- [#2288](https://github.com/rails-api/active_model_serializers/pull/2288)
|
||||||
|
Change the fetch method to deal with recyclable key cache strategy.
|
||||||
|
Fixes #2287. (@cintamani, @wasifhossain)
|
||||||
|
- [#2307](https://github.com/rails-api/active_model_serializers/pull/2307) Falsey attribute values should not be reevaluated.
|
||||||
|
|
||||||
|
Misc:
|
||||||
|
|
||||||
|
- [#2309](https://github.com/rails-api/active_model_serializers/pull/2309) Performance and memory usage fixes
|
||||||
|
|
||||||
|
### [v0.10.8 (2018-11-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.7...v0.10.8)
|
||||||
|
|
||||||
|
Features:
|
||||||
|
- [#2279](https://github.com/rails-api/active_model_serializers/pull/2279) Support condition options in serializer link statements
|
||||||
|
|
||||||
|
Fixes:
|
||||||
|
|
||||||
|
- [#2296](https://github.com/rails-api/active_model_serializers/pull/2296) Fixes #2295 (@Hirurg103)
|
||||||
|
- Fix finding of namespaced serializer and non-namespaced model.
|
||||||
|
- [#2289](https://github.com/rails-api/active_model_serializers/pull/2289) Fixes #2255 (@f-mer)
|
||||||
|
- Fix autoloading race condition, especially in Rails 5.
|
||||||
|
- [#2299](https://github.com/rails-api/active_model_serializers/pull/2299) Fixes #2270 (@chau-bao-long via #2276)
|
||||||
|
- Fix reflection thread-safety bug
|
||||||
|
|
||||||
|
### [v0.10.7 (2017-11-14)](https://github.com/rails-api/active_model_serializers/compare/v0.10.6...v0.10.7)
|
||||||
|
|
||||||
|
Regressions Fixed From v0.10.6:
|
||||||
|
|
||||||
|
- [#2211](https://github.com/rails-api/active_model_serializers/pull/2211). Fixes #2125, #2160. (@bf4)
|
||||||
|
- Fix polymorphic belongs_to tests; passes on v0.10.5, fails on v0.10.6
|
||||||
|
- Fix JSON:API polymorphic type regression from v0.10.5
|
||||||
|
- Fix JSON:API: for_type_and_id should always inflect_type
|
||||||
|
```
|
||||||
|
Should Serializer._type ever be inflected?
|
||||||
|
Right now, it won't be, but association.serializer._type will be inflected.
|
||||||
|
|
||||||
|
That's the current behavior.
|
||||||
|
```
|
||||||
|
- [#2216](https://github.com/rails-api/active_model_serializers/pull/2216). Fixes #2132, #2180. (@bf4)
|
||||||
|
- Fix JSON:API: Serialize resource type for unpersisted records (blank id)
|
||||||
|
- [#2218](https://github.com/rails-api/active_model_serializers/pull/2218). Fixes #2178. (@bf4)
|
||||||
|
- Fix JSON:API: Make using foreign key on belongs_to opt-in. No effect on polymorphic relationships.
|
||||||
|
```
|
||||||
|
# set to true to opt-in
|
||||||
|
ActiveModelSerializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship = true
|
||||||
|
```
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
- [#2136](https://github.com/rails-api/active_model_serializers/pull/2136) Enable inclusion of sideloaded relationship objects by `key`. (@caomania)
|
||||||
|
- [#2021](https://github.com/rails-api/active_model_serializers/pull/2021) ActiveModelSerializers::Model#attributes. Originally in [#1982](https://github.com/rails-api/active_model_serializers/pull/1982). (@bf4)
|
||||||
|
- [#2130](https://github.com/rails-api/active_model_serializers/pull/2130) Allow serialized ID to be overwritten for belongs-to relationships. (@greysteil)
|
||||||
|
- [#2189](https://github.com/rails-api/active_model_serializers/pull/2189)
|
||||||
|
Update version constraint for jsonapi-renderer to `['>= 0.1.1.beta1', '< 0.3']`
|
||||||
|
(@tagliala)
|
||||||
|
|
||||||
|
Fixes:
|
||||||
|
|
||||||
|
- [#2022](https://github.com/rails-api/active_model_serializers/pull/2022) Mutation of ActiveModelSerializers::Model now changes the attributes. Originally in [#1984](https://github.com/rails-api/active_model_serializers/pull/1984). (@bf4)
|
||||||
|
- [#2200](https://github.com/rails-api/active_model_serializers/pull/2200) Fix deserialization of polymorphic relationships. (@dennis95stumm)
|
||||||
|
- [#2214](https://github.com/rails-api/active_model_serializers/pull/2214) Fail if unable to infer collection type with json adapter. (@jmeredith16)
|
||||||
|
- [#2149](https://github.com/rails-api/active_model_serializers/pull/2149) Always include self, first, last pagination link. (@mecampbellsoup)
|
||||||
|
- [#2179](https://github.com/rails-api/active_model_serializers/pull/2179) Fixes #2173, Pass block to Enumerator.new. (@drn)
|
||||||
|
|
||||||
|
Misc:
|
||||||
|
|
||||||
|
- [#2176](https://github.com/rails-api/active_model_serializers/pull/2176) Documentation for global adapter config. (@mrpinsky)
|
||||||
|
- [#2215](https://github.com/rails-api/active_model_serializers/pull/2215) Update `serializers.md` documentation to denote alternate use cases for `scope`. (@stratigos)
|
||||||
|
- [#2212](https://github.com/rails-api/active_model_serializers/pull/2212) Remove legacy has_many_embed_ids test. (@bf4)
|
||||||
|
|
||||||
### [v0.10.6 (2017-05-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.5...v0.10.6)
|
### [v0.10.6 (2017-05-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.5...v0.10.6)
|
||||||
|
|
||||||
Fixes:
|
Fixes:
|
||||||
|
|||||||
26
Gemfile
26
Gemfile
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
#
|
#
|
||||||
# Add a Gemfile.local to locally bundle gems outside of version control
|
# Add a Gemfile.local to locally bundle gems outside of version control
|
||||||
@ -12,6 +14,7 @@ version = ENV['RAILS_VERSION'] || '4.2'
|
|||||||
if version == 'master'
|
if version == 'master'
|
||||||
gem 'rack', github: 'rack/rack'
|
gem 'rack', github: 'rack/rack'
|
||||||
gem 'arel', github: 'rails/arel'
|
gem 'arel', github: 'rails/arel'
|
||||||
|
gem 'rails', github: 'rails/rails'
|
||||||
git 'https://github.com/rails/rails.git' do
|
git 'https://github.com/rails/rails.git' do
|
||||||
gem 'railties'
|
gem 'railties'
|
||||||
gem 'activesupport'
|
gem 'activesupport'
|
||||||
@ -23,6 +26,7 @@ if version == 'master'
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
gem_version = "~> #{version}.0"
|
gem_version = "~> #{version}.0"
|
||||||
|
gem 'rails', gem_version
|
||||||
gem 'railties', gem_version
|
gem 'railties', gem_version
|
||||||
gem 'activesupport', gem_version
|
gem 'activesupport', gem_version
|
||||||
gem 'activemodel', gem_version
|
gem 'activemodel', gem_version
|
||||||
@ -36,18 +40,32 @@ end
|
|||||||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
||||||
gem 'tzinfo-data', platforms: (@windows_platforms + [:jruby])
|
gem 'tzinfo-data', platforms: (@windows_platforms + [:jruby])
|
||||||
|
|
||||||
|
if ENV['CI']
|
||||||
|
if RUBY_VERSION < '2.4'
|
||||||
|
# Windows: An error occurred while installing nokogiri (1.8.0)
|
||||||
|
gem 'nokogiri', '< 1.7', platforms: @windows_platforms
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
group :bench do
|
group :bench do
|
||||||
# https://github.com/rails-api/active_model_serializers/commit/cb4459580a6f4f37f629bf3185a5224c8624ca76
|
# https://github.com/rails-api/active_model_serializers/commit/cb4459580a6f4f37f629bf3185a5224c8624ca76
|
||||||
gem 'benchmark-ips', '>= 2.7.2', require: false, group: :development
|
gem 'benchmark-ips', '>= 2.7.2', require: false, group: :development
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'sqlite3', platform: (@windows_platforms + [:ruby])
|
gem 'sqlite3', '~> 1.3.13', platform: (@windows_platforms + [:ruby])
|
||||||
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
|
platforms :jruby do
|
||||||
|
if version == 'master' || version >= '5'
|
||||||
|
gem 'activerecord-jdbcsqlite3-adapter', '~> 50'
|
||||||
|
else
|
||||||
|
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.0'
|
||||||
|
end
|
||||||
|
end
|
||||||
gem 'codeclimate-test-reporter', require: false
|
gem 'codeclimate-test-reporter', require: false
|
||||||
gem 'm', '~> 1.5'
|
gem 'm', '~> 1.5'
|
||||||
gem 'pry', '~> 0.10'
|
gem 'pry', '>= 0.10'
|
||||||
gem 'pry-byebug', '~> 3.4', platform: :ruby
|
gem 'byebug', '~> 8.2' if RUBY_VERSION < '2.2'
|
||||||
|
gem 'pry-byebug', platform: :ruby
|
||||||
end
|
end
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
|
|||||||
@ -49,8 +49,6 @@ Check how to change the adapter in the sections below.
|
|||||||
`0.10.x` is based on the `0.8.0` code, but with a more flexible
|
`0.10.x` is based on the `0.8.0` code, but with a more flexible
|
||||||
architecture. We'd love your help. [Learn how you can help here.](CONTRIBUTING.md)
|
architecture. We'd love your help. [Learn how you can help here.](CONTRIBUTING.md)
|
||||||
|
|
||||||
It is generally safe and recommended to use the master branch.
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Add this line to your application's Gemfile:
|
Add this line to your application's Gemfile:
|
||||||
@ -187,7 +185,7 @@ and, if there is no serializer, primitives.
|
|||||||
|
|
||||||
### ActiveModelSerializers::Adapter::Base
|
### ActiveModelSerializers::Adapter::Base
|
||||||
|
|
||||||
The **`ActiveModelSerializeres::Adapter::Base`** describes the structure of the JSON document generated from a
|
The **`ActiveModelSerializers::Adapter::Base`** describes the structure of the JSON document generated from a
|
||||||
serializer. For example, the `Attributes` example represents each serializer as its
|
serializer. For example, the `Attributes` example represents each serializer as its
|
||||||
unmodified attributes. The `JsonApi` adapter represents the serializer as a [JSON
|
unmodified attributes. The `JsonApi` adapter represents the serializer as a [JSON
|
||||||
API](http://jsonapi.org/) document.
|
API](http://jsonapi.org/) document.
|
||||||
@ -268,8 +266,8 @@ to know about, but not part of ActiveModelSerializers.)
|
|||||||
|
|
||||||
- An `ActiveRecord::Base` object.
|
- An `ActiveRecord::Base` object.
|
||||||
- Any Ruby object that passes the
|
- Any Ruby object that passes the
|
||||||
[Lint](http://www.rubydoc.info/github/rails-api/active_model_serializers/ActiveModel/Serializer/Lint/Tests)
|
[Lint](https://www.rubydoc.info/gems/active_model_serializers/ActiveModel/Serializer/Lint/Tests)
|
||||||
[code](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer/lint.rb).
|
[(code)](lib/active_model/serializer/lint.rb).
|
||||||
|
|
||||||
ActiveModelSerializers provides a
|
ActiveModelSerializers provides a
|
||||||
[`ActiveModelSerializers::Model`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model_serializers/model.rb),
|
[`ActiveModelSerializers::Model`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model_serializers/model.rb),
|
||||||
|
|||||||
2
Rakefile
2
Rakefile
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
lib = File.expand_path('../lib', __FILE__)
|
lib = File.expand_path('../lib', __FILE__)
|
||||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||||
@ -39,10 +40,10 @@ Gem::Specification.new do |spec|
|
|||||||
# 'activesupport', rails_versions
|
# 'activesupport', rails_versions
|
||||||
# 'i18n,
|
# 'i18n,
|
||||||
# 'tzinfo'
|
# 'tzinfo'
|
||||||
# 'minitest'
|
spec.add_development_dependency 'minitest', ['~> 5.0', '< 5.11']
|
||||||
# 'thread_safe'
|
# 'thread_safe'
|
||||||
|
|
||||||
spec.add_runtime_dependency 'jsonapi-renderer', ['>= 0.1.1.beta1', '< 0.2']
|
spec.add_runtime_dependency 'jsonapi-renderer', ['>= 0.1.1.beta1', '< 0.3']
|
||||||
spec.add_runtime_dependency 'case_transform', '>= 0.2'
|
spec.add_runtime_dependency 'case_transform', '>= 0.2'
|
||||||
|
|
||||||
spec.add_development_dependency 'activerecord', rails_versions
|
spec.add_development_dependency 'activerecord', rails_versions
|
||||||
|
|||||||
10
appveyor.yml
10
appveyor.yml
@ -5,19 +5,17 @@ skip_tags: true
|
|||||||
environment:
|
environment:
|
||||||
JRUBY_OPTS: "--dev -J-Xmx1024M --debug"
|
JRUBY_OPTS: "--dev -J-Xmx1024M --debug"
|
||||||
matrix:
|
matrix:
|
||||||
- ruby_version: "Ruby21"
|
- ruby_version: "Ruby23"
|
||||||
- ruby_version: "Ruby21-x64"
|
- ruby_version: "Ruby23-x64"
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
- vendor/bundle
|
- vendor/bundle
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- SET PATH=C:\%ruby_version%\bin;%PATH%
|
- SET PATH=C:\%ruby_version%\bin;%PATH%
|
||||||
- gem update --system
|
|
||||||
- gem uninstall bundler -a -x
|
|
||||||
- gem install bundler -v 1.13.7
|
|
||||||
- bundle env
|
- bundle env
|
||||||
- bundle install --path=vendor/bundle --retry=3 --jobs=3
|
- bundle check || bundle install --path=vendor/bundle --retry=3 --jobs=3
|
||||||
|
- bundle clean --force
|
||||||
|
|
||||||
before_test:
|
before_test:
|
||||||
- ruby -v
|
- ruby -v
|
||||||
|
|||||||
@ -36,6 +36,12 @@ The `Attributes` adapter does not include a root key. It is just the serialized
|
|||||||
|
|
||||||
Use either the `JSON` or `JSON API` adapters if you want the response document to have a root key.
|
Use either the `JSON` or `JSON API` adapters if you want the response document to have a root key.
|
||||||
|
|
||||||
|
***IMPORTANT***: Adapter configuration has *no effect* on a serializer instance
|
||||||
|
being used directly. That is, `UserSerializer.new(user).as_json` will *always*
|
||||||
|
behave as if the adapter were the 'Attributes' adapter. See [Outside Controller
|
||||||
|
Usage](../howto/outside_controller_use.md) for more details on recommended
|
||||||
|
usage.
|
||||||
|
|
||||||
## Built in Adapters
|
## Built in Adapters
|
||||||
|
|
||||||
### Attributes - Default
|
### Attributes - Default
|
||||||
|
|||||||
@ -57,6 +57,7 @@ still prefer the render option `:key_transform` over this setting.
|
|||||||
application, setting `config.key_transform` to `:unaltered` will provide a performance boost.*
|
application, setting `config.key_transform` to `:unaltered` will provide a performance boost.*
|
||||||
|
|
||||||
##### default_includes
|
##### default_includes
|
||||||
|
|
||||||
What relationships to serialize by default. Default: `'*'`, which includes one level of related
|
What relationships to serialize by default. Default: `'*'`, which includes one level of related
|
||||||
objects. See [includes](adapters.md#included) for more info.
|
objects. See [includes](adapters.md#included) for more info.
|
||||||
|
|
||||||
@ -162,6 +163,21 @@ Default: `{}`.
|
|||||||
|
|
||||||
*Used when `jsonapi_include_toplevel_object` is `true`*
|
*Used when `jsonapi_include_toplevel_object` is `true`*
|
||||||
|
|
||||||
|
##### jsonapi_use_foreign_key_on_belongs_to_relationship
|
||||||
|
|
||||||
|
When true, the relationship will determine its resource object identifier
|
||||||
|
without calling the association or its serializer. This can be useful when calling
|
||||||
|
the association object is triggering unnecessary queries.
|
||||||
|
|
||||||
|
For example, if a `comment` belongs to a `post`, and the comment
|
||||||
|
uses the foreign key `post_id`, we can determine the resource object
|
||||||
|
identifier `id` as `comment.post_id` and the `type` from the association options.
|
||||||
|
Or quite simply, it behaves as `belongs_to :post, type: :posts, foreign_key: :post_id`.
|
||||||
|
|
||||||
|
Note: This option has *no effect* on polymorphic associations as we cannot reliably
|
||||||
|
determine the associated object's type without instantiating it.
|
||||||
|
|
||||||
|
Default: `false`.
|
||||||
|
|
||||||
## Hooks
|
## Hooks
|
||||||
|
|
||||||
|
|||||||
@ -290,4 +290,4 @@ See [Usage outside of a controller](../howto/outside_controller_use.md#serializi
|
|||||||
|
|
||||||
## Pagination
|
## Pagination
|
||||||
|
|
||||||
See [How to add pagination links](https://github.com/rails-api/active_model_serializers/blob/master/docs/howto/add_pagination_links.md).
|
See [How to add pagination links](../howto/add_pagination_links.md).
|
||||||
|
|||||||
@ -65,7 +65,7 @@ Where:
|
|||||||
- `virtual_value:`
|
- `virtual_value:`
|
||||||
- `polymorphic:` defines if polymorphic relation type should be nested in serialized association.
|
- `polymorphic:` defines if polymorphic relation type should be nested in serialized association.
|
||||||
- `type:` the resource type as used by JSON:API, especially on a `belongs_to` relationship.
|
- `type:` the resource type as used by JSON:API, especially on a `belongs_to` relationship.
|
||||||
- `class_name:` used to determine `type` when `type` not given
|
- `class_name:` the (String) model name used to determine `type`, when `type` is not given. e.g. `class_name: "Comment"` would imply the type `comments`
|
||||||
- `foreign_key:` used by JSON:API on a `belongs_to` relationship to avoid unnecessarily loading the association object.
|
- `foreign_key:` used by JSON:API on a `belongs_to` relationship to avoid unnecessarily loading the association object.
|
||||||
- `namespace:` used when looking up the serializer and `serializer` is not given. Falls back to the parent serializer's `:namespace` instance options, which, when present, comes from the render options. See [Rendering#namespace](rendering.md#namespace] for more details.
|
- `namespace:` used when looking up the serializer and `serializer` is not given. Falls back to the parent serializer's `:namespace` instance options, which, when present, comes from the render options. See [Rendering#namespace](rendering.md#namespace] for more details.
|
||||||
- optional: `&block` is a context that returns the association's attributes.
|
- optional: `&block` is a context that returns the association's attributes.
|
||||||
@ -81,6 +81,7 @@ e.g.
|
|||||||
```ruby
|
```ruby
|
||||||
has_one :bio
|
has_one :bio
|
||||||
has_one :blog, key: :site
|
has_one :blog, key: :site
|
||||||
|
has_one :blog, class_name: "Blog"
|
||||||
has_one :maker, virtual_value: { id: 1 }
|
has_one :maker, virtual_value: { id: 1 }
|
||||||
|
|
||||||
has_one :blog do |serializer|
|
has_one :blog do |serializer|
|
||||||
@ -114,6 +115,7 @@ e.g.
|
|||||||
has_many :comments
|
has_many :comments
|
||||||
has_many :comments, key: :reviews
|
has_many :comments, key: :reviews
|
||||||
has_many :comments, serializer: CommentPreviewSerializer
|
has_many :comments, serializer: CommentPreviewSerializer
|
||||||
|
has_many :comments, class_name: "Comment"
|
||||||
has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
|
has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
|
||||||
has_many :comments, key: :last_comments do
|
has_many :comments, key: :last_comments do
|
||||||
last(1)
|
last(1)
|
||||||
@ -127,6 +129,7 @@ e.g.
|
|||||||
```ruby
|
```ruby
|
||||||
belongs_to :author, serializer: AuthorPreviewSerializer
|
belongs_to :author, serializer: AuthorPreviewSerializer
|
||||||
belongs_to :author, key: :writer
|
belongs_to :author, key: :writer
|
||||||
|
belongs_to :author, class_name: "Author"
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
belongs_to :blog
|
belongs_to :blog
|
||||||
def blog
|
def blog
|
||||||
@ -235,6 +238,15 @@ link :other, 'https://example.com/resource'
|
|||||||
link(:posts) { link_author_posts_url(object) }
|
link(:posts) { link_author_posts_url(object) }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Just like attributes, links also support conditions in options
|
||||||
|
```ruby
|
||||||
|
link(:secret, if: :internal?) { object.secret_link }
|
||||||
|
|
||||||
|
def internal?
|
||||||
|
instance_options[:context] == :internal
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
#### #object
|
#### #object
|
||||||
|
|
||||||
The object being serialized.
|
The object being serialized.
|
||||||
@ -294,6 +306,8 @@ end
|
|||||||
Whether you write the method as above or as `object.comments.where(created_by: scope)`
|
Whether you write the method as above or as `object.comments.where(created_by: scope)`
|
||||||
is a matter of preference (assuming `scope_name` has been set).
|
is a matter of preference (assuming `scope_name` has been set).
|
||||||
|
|
||||||
|
Keep in mind that the scope can be set to any available controller reference. This can be utilized to provide access to any other data scopes or presentation helpers.
|
||||||
|
|
||||||
##### Controller Authorization Context
|
##### Controller Authorization Context
|
||||||
|
|
||||||
In the controller, the scope/scope_name options are equal to
|
In the controller, the scope/scope_name options are equal to
|
||||||
@ -311,7 +325,7 @@ current authorization scope when you call `render :json`.
|
|||||||
called on every request. This was [also a problem](https://github.com/rails-api/active_model_serializers/pull/1252#issuecomment-159810477)
|
called on every request. This was [also a problem](https://github.com/rails-api/active_model_serializers/pull/1252#issuecomment-159810477)
|
||||||
in [`0.9`](https://github.com/rails-api/active_model_serializers/tree/0-9-stable#customizing-scope).
|
in [`0.9`](https://github.com/rails-api/active_model_serializers/tree/0-9-stable#customizing-scope).
|
||||||
|
|
||||||
We can change the scope from `current_user` to `view_context`.
|
We can change the scope from `current_user` to `view_context`, which is included in subclasses of `ActionController::Base`.
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
class SomeController < ActionController::Base
|
class SomeController < ActionController::Base
|
||||||
@ -379,6 +393,7 @@ class PostsController < ActionController::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
Note that any controller reference which provides the desired scope is acceptable, such as another controller method for loading a different resource or reference to helpers. For example, `ActionController::API` does not include `ActionView::ViewContext`, and would need a different reference for passing any helpers into a serializer via `serialization_scope`.
|
||||||
|
|
||||||
#### #read_attribute_for_serialization(key)
|
#### #read_attribute_for_serialization(key)
|
||||||
|
|
||||||
@ -471,7 +486,7 @@ the `ActiveModel::Serializer.serializer_for` method to return a serializer class
|
|||||||
```ruby
|
```ruby
|
||||||
class MySerializer < ActiveModel::Serializer
|
class MySerializer < ActiveModel::Serializer
|
||||||
def self.serializer_for(model, options)
|
def self.serializer_for(model, options)
|
||||||
return SparseAdminSerializer if model.class == 'Admin'
|
return SparseAdminSerializer if model.class.name == 'Admin'
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,13 @@ In order to add the root key you need to use the ```JSON``` Adapter, you can cha
|
|||||||
ActiveModelSerializers.config.adapter = :json
|
ActiveModelSerializers.config.adapter = :json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that adapter configuration has no effect on a serializer that is called
|
||||||
|
directly, e.g. in a serializer unit test. Instead, something like
|
||||||
|
`UserSerializer.new(user).as_json` will *always* behave as if the adapter were
|
||||||
|
the 'Attributes' adapter. See [Outside Controller
|
||||||
|
Usage](../howto/outside_controller_use.md) for more details on recommended
|
||||||
|
usage.
|
||||||
|
|
||||||
You can also specify a class as adapter, as long as it complies with the ActiveModelSerializers adapters interface.
|
You can also specify a class as adapter, as long as it complies with the ActiveModelSerializers adapters interface.
|
||||||
It will add the root key to all your serialized endpoints.
|
It will add the root key to all your serialized endpoints.
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'active_support/core_ext/class/attribute'
|
require 'active_support/core_ext/class/attribute'
|
||||||
require 'active_model_serializers/serialization_context'
|
require 'active_model_serializers/serialization_context'
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'set'
|
require 'set'
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'thread_safe'
|
require 'thread_safe'
|
||||||
require 'jsonapi/include_directive'
|
require 'jsonapi/include_directive'
|
||||||
require 'active_model/serializer/collection_serializer'
|
require 'active_model/serializer/collection_serializer'
|
||||||
@ -18,16 +20,17 @@ module ActiveModel
|
|||||||
# @see #serializable_hash for more details on these valid keys.
|
# @see #serializable_hash for more details on these valid keys.
|
||||||
SERIALIZABLE_HASH_VALID_KEYS = [:only, :except, :methods, :include, :root].freeze
|
SERIALIZABLE_HASH_VALID_KEYS = [:only, :except, :methods, :include, :root].freeze
|
||||||
extend ActiveSupport::Autoload
|
extend ActiveSupport::Autoload
|
||||||
|
eager_autoload do
|
||||||
autoload :Adapter
|
autoload :Adapter
|
||||||
autoload :Null
|
autoload :Null
|
||||||
autoload :Attribute
|
autoload :Attribute
|
||||||
|
autoload :Link
|
||||||
autoload :Association
|
autoload :Association
|
||||||
autoload :Reflection
|
autoload :Reflection
|
||||||
autoload :SingularReflection
|
|
||||||
autoload :CollectionReflection
|
|
||||||
autoload :BelongsToReflection
|
autoload :BelongsToReflection
|
||||||
autoload :HasOneReflection
|
autoload :HasOneReflection
|
||||||
autoload :HasManyReflection
|
autoload :HasManyReflection
|
||||||
|
end
|
||||||
include ActiveSupport::Configurable
|
include ActiveSupport::Configurable
|
||||||
include Caching
|
include Caching
|
||||||
|
|
||||||
@ -142,6 +145,7 @@ module ActiveModel
|
|||||||
# Make JSON API top-level jsonapi member opt-in
|
# Make JSON API top-level jsonapi member opt-in
|
||||||
# ref: http://jsonapi.org/format/#document-top-level
|
# ref: http://jsonapi.org/format/#document-top-level
|
||||||
config.jsonapi_include_toplevel_object = false
|
config.jsonapi_include_toplevel_object = false
|
||||||
|
config.jsonapi_use_foreign_key_on_belongs_to_relationship = false
|
||||||
config.include_data_default = true
|
config.include_data_default = true
|
||||||
|
|
||||||
# For configuring how serializers are found.
|
# For configuring how serializers are found.
|
||||||
@ -274,9 +278,14 @@ module ActiveModel
|
|||||||
# link(:self) { "http://example.com/resource/#{object.id}" }
|
# link(:self) { "http://example.com/resource/#{object.id}" }
|
||||||
# @example
|
# @example
|
||||||
# link :resource, "http://example.com/resource"
|
# link :resource, "http://example.com/resource"
|
||||||
|
# @example
|
||||||
|
# link(:callback, if: :internal?), { "http://example.com/callback" }
|
||||||
#
|
#
|
||||||
def self.link(name, value = nil, &block)
|
def self.link(name, *args, &block)
|
||||||
_links[name] = block || value
|
options = args.extract_options!
|
||||||
|
# For compatibility with the use case of passing link directly as string argument
|
||||||
|
# without block, we are creating a wrapping block
|
||||||
|
_links[name] = Link.new(name, options, block || ->(_serializer) { args.first })
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the JSON API meta attribute of a serializer.
|
# Set the JSON API meta attribute of a serializer.
|
||||||
@ -337,10 +346,10 @@ module ActiveModel
|
|||||||
# @return [Enumerator<Association>]
|
# @return [Enumerator<Association>]
|
||||||
def associations(include_directive = ActiveModelSerializers.default_include_directive, include_slice = nil)
|
def associations(include_directive = ActiveModelSerializers.default_include_directive, include_slice = nil)
|
||||||
include_slice ||= include_directive
|
include_slice ||= include_directive
|
||||||
return Enumerator.new unless object
|
return Enumerator.new {} unless object
|
||||||
|
|
||||||
Enumerator.new do |y|
|
Enumerator.new do |y|
|
||||||
self.class._reflections.each do |key, reflection|
|
(self.instance_reflections ||= self.class._reflections.deep_dup).each do |key, reflection|
|
||||||
next if reflection.excluded?(self)
|
next if reflection.excluded?(self)
|
||||||
next unless include_directive.key?(key)
|
next unless include_directive.key?(key)
|
||||||
|
|
||||||
@ -404,6 +413,6 @@ module ActiveModel
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
attr_accessor :instance_options
|
attr_accessor :instance_options, :instance_reflections
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'active_model_serializers/adapter'
|
require 'active_model_serializers/adapter'
|
||||||
require 'active_model_serializers/deprecate'
|
require 'active_model_serializers/deprecate'
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
module Adapter
|
module Adapter
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
module Adapter
|
module Adapter
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
module Adapter
|
module Adapter
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
module Adapter
|
module Adapter
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
module Adapter
|
module Adapter
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'active_model/serializer/collection_serializer'
|
require 'active_model/serializer/collection_serializer'
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'active_model/serializer/lazy_association'
|
require 'active_model/serializer/lazy_association'
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'active_model/serializer/field'
|
require 'active_model/serializer/field'
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
# @api private
|
# @api private
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class CollectionSerializer
|
class CollectionSerializer
|
||||||
@ -19,11 +21,10 @@ module ActiveModel
|
|||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
def serializable_hash(adapter_options, options, adapter_instance)
|
def serializable_hash(adapter_options, options, adapter_instance)
|
||||||
include_directive = ActiveModel::Serializer.include_directive_from_options(adapter_options)
|
options[:include_directive] ||= ActiveModel::Serializer.include_directive_from_options(adapter_options)
|
||||||
adapter_options[:cached_attributes] ||= ActiveModel::Serializer.cache_read_multi(self, adapter_instance, include_directive)
|
options[:cached_attributes] ||= ActiveModel::Serializer.cache_read_multi(self, adapter_instance, options[:include_directive])
|
||||||
adapter_opts = adapter_options.merge(include_directive: include_directive)
|
|
||||||
serializers.map do |serializer|
|
serializers.map do |serializer|
|
||||||
serializer.serializable_hash(adapter_opts, options, adapter_instance)
|
serializer.serializable_hash(adapter_options, options, adapter_instance)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,7 +47,9 @@ module ActiveModel
|
|||||||
# 3. get from collection name, if a named collection
|
# 3. get from collection name, if a named collection
|
||||||
key ||= object.respond_to?(:name) ? object.name && object.name.underscore : nil
|
key ||= object.respond_to?(:name) ? object.name && object.name.underscore : nil
|
||||||
# 4. key may be nil for empty collection and no serializer option
|
# 4. key may be nil for empty collection and no serializer option
|
||||||
key && key.pluralize
|
key &&= key.pluralize
|
||||||
|
# 5. fail if the key cannot be determined
|
||||||
|
key || fail(ArgumentError, 'Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String')
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/CyclomaticComplexity
|
# rubocop:enable Metrics/CyclomaticComplexity
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
UndefinedCacheKey = Class.new(StandardError)
|
UndefinedCacheKey = Class.new(StandardError)
|
||||||
@ -281,7 +283,9 @@ module ActiveModel
|
|||||||
# Use object's cache_key if available, else derive a key from the object
|
# Use object's cache_key if available, else derive a key from the object
|
||||||
# Pass the `key` option to the `cache` declaration or override this method to customize the cache key
|
# Pass the `key` option to the `cache` declaration or override this method to customize the cache key
|
||||||
def object_cache_key
|
def object_cache_key
|
||||||
if object.respond_to?(:cache_key)
|
if object.respond_to?(:cache_key_with_version)
|
||||||
|
object.cache_key_with_version
|
||||||
|
elsif object.respond_to?(:cache_key)
|
||||||
object.cache_key
|
object.cache_key
|
||||||
elsif (serializer_cache_key = (serializer_class._cache_key || serializer_class._cache_options[:key]))
|
elsif (serializer_cache_key = (serializer_class._cache_key || serializer_class._cache_options[:key]))
|
||||||
object_time_safe = object.updated_at
|
object_time_safe = object.updated_at
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class ErrorSerializer < ActiveModel::Serializer
|
class ErrorSerializer < ActiveModel::Serializer
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'active_model/serializer/error_serializer'
|
require 'active_model/serializer/error_serializer'
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
# Holds all the meta-data about a field (i.e. attribute or association) as it was
|
# Holds all the meta-data about a field (i.e. attribute or association) as it was
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class Fieldset
|
class Fieldset
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
# @api private
|
# @api private
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
# @api private
|
# @api private
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
# @api private
|
# @api private
|
||||||
@ -7,11 +9,12 @@ module ActiveModel
|
|||||||
delegate :collection?, to: :reflection
|
delegate :collection?, to: :reflection
|
||||||
|
|
||||||
def reflection_options
|
def reflection_options
|
||||||
@reflection_options ||= reflection.options.dup.reject { |k, _| !REFLECTION_OPTIONS.include?(k) }
|
@reflection_options ||= reflection.options.select { |k, _| REFLECTION_OPTIONS.include?(k) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def object
|
def object
|
||||||
@object ||= reflection.value(
|
return @object if defined?(@object)
|
||||||
|
@object = reflection.value(
|
||||||
association_options.fetch(:parent_serializer),
|
association_options.fetch(:parent_serializer),
|
||||||
association_options.fetch(:include_slice)
|
association_options.fetch(:include_slice)
|
||||||
)
|
)
|
||||||
@ -76,6 +79,7 @@ module ActiveModel
|
|||||||
serializer_options[:serializer_context_class] = association_options.fetch(:parent_serializer).class
|
serializer_options[:serializer_context_class] = association_options.fetch(:parent_serializer).class
|
||||||
serializer = reflection_options.fetch(:serializer, nil)
|
serializer = reflection_options.fetch(:serializer, nil)
|
||||||
serializer_options[:serializer] = serializer if serializer
|
serializer_options[:serializer] = serializer if serializer
|
||||||
|
serializer_options[:namespace] = reflection_options[:namespace] if reflection_options[:namespace]
|
||||||
serializer_class.new(object, serializer_options)
|
serializer_class.new(object, serializer_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
23
lib/active_model/serializer/link.rb
Normal file
23
lib/active_model/serializer/link.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'active_model/serializer/field'
|
||||||
|
|
||||||
|
module ActiveModel
|
||||||
|
class Serializer
|
||||||
|
# Holds all the data about a serializer link
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# class PostSerializer < ActiveModel::Serializer
|
||||||
|
# link :callback, if: :internal? do
|
||||||
|
# object.callback_link
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# def internal?
|
||||||
|
# instance_options[:internal] == true
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
class Link < Field
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
module Lint
|
module Lint
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class Null < Serializer
|
class Null < Serializer
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'active_model/serializer/field'
|
require 'active_model/serializer/field'
|
||||||
require 'active_model/serializer/association'
|
require 'active_model/serializer/association'
|
||||||
|
|
||||||
@ -140,7 +142,7 @@ module ActiveModel
|
|||||||
def include_data?(include_slice)
|
def include_data?(include_slice)
|
||||||
include_data_setting = options[:include_data_setting]
|
include_data_setting = options[:include_data_setting]
|
||||||
case include_data_setting
|
case include_data_setting
|
||||||
when :if_sideloaded then include_slice.key?(name)
|
when :if_sideloaded then include_slice.key?(options.fetch(:key, name))
|
||||||
when true then true
|
when true then true
|
||||||
when false then false
|
when false then false
|
||||||
else fail ArgumentError, "Unknown include_data_setting '#{include_data_setting.inspect}'"
|
else fail ArgumentError, "Unknown include_data_setting '#{include_data_setting.inspect}'"
|
||||||
@ -151,6 +153,9 @@ module ActiveModel
|
|||||||
# @yield [ActiveModel::Serializer]
|
# @yield [ActiveModel::Serializer]
|
||||||
# @return [:nil, associated resource or resource collection]
|
# @return [:nil, associated resource or resource collection]
|
||||||
def value(serializer, include_slice)
|
def value(serializer, include_slice)
|
||||||
|
# NOTE(BF): This method isn't thread-safe because the _reflections class attribute is not thread-safe
|
||||||
|
# Therefore, when we build associations from reflections, we dup the entire reflection instance.
|
||||||
|
# Better solutions much appreciated!
|
||||||
@object = serializer.object
|
@object = serializer.object
|
||||||
@scope = serializer.scope
|
@scope = serializer.scope
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
VERSION = '0.10.6'.freeze
|
VERSION = '0.10.9'.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'active_model'
|
require 'active_model'
|
||||||
require 'active_support'
|
require 'active_support'
|
||||||
require 'active_support/core_ext/object/with_options'
|
require 'active_support/core_ext/object/with_options'
|
||||||
@ -5,16 +7,19 @@ require 'active_support/core_ext/string/inflections'
|
|||||||
require 'active_support/json'
|
require 'active_support/json'
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
extend ActiveSupport::Autoload
|
extend ActiveSupport::Autoload
|
||||||
|
eager_autoload do
|
||||||
autoload :Model
|
autoload :Model
|
||||||
autoload :Callbacks
|
autoload :Callbacks
|
||||||
autoload :Deserialization
|
|
||||||
autoload :SerializableResource
|
autoload :SerializableResource
|
||||||
|
autoload :SerializationContext
|
||||||
autoload :Logging
|
autoload :Logging
|
||||||
autoload :Test
|
autoload :Test
|
||||||
autoload :Adapter
|
autoload :Adapter
|
||||||
autoload :JsonPointer
|
autoload :JsonPointer
|
||||||
autoload :Deprecate
|
autoload :Deprecate
|
||||||
autoload :LookupChain
|
autoload :LookupChain
|
||||||
|
autoload :Deserialization
|
||||||
|
end
|
||||||
|
|
||||||
class << self; attr_accessor :logger; end
|
class << self; attr_accessor :logger; end
|
||||||
self.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
|
self.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
|
||||||
@ -46,8 +51,13 @@ module ActiveModelSerializers
|
|||||||
$VERBOSE = original_verbose
|
$VERBOSE = original_verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.eager_load!
|
||||||
|
super
|
||||||
|
ActiveModel::Serializer.eager_load!
|
||||||
|
end
|
||||||
|
|
||||||
require 'active_model/serializer/version'
|
require 'active_model/serializer/version'
|
||||||
require 'active_model/serializer'
|
require 'active_model/serializer'
|
||||||
require 'active_model/serializable_resource'
|
require 'active_model/serializable_resource'
|
||||||
require 'active_model_serializers/railtie' if defined?(::Rails)
|
require 'active_model_serializers/railtie' if defined?(::Rails::Railtie)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
UnknownAdapterError = Class.new(ArgumentError)
|
UnknownAdapterError = Class.new(ArgumentError)
|
||||||
@ -35,7 +37,7 @@ module ActiveModelSerializers
|
|||||||
|
|
||||||
# @return [Array<Symbol>] list of adapter names
|
# @return [Array<Symbol>] list of adapter names
|
||||||
def adapters
|
def adapters
|
||||||
adapter_map.keys.sort
|
adapter_map.keys.sort!
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds an adapter 'klass' with 'name' to the 'adapter_map'
|
# Adds an adapter 'klass' with 'name' to the 'adapter_map'
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class Attributes < Base
|
class Attributes < Base
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'case_transform'
|
require 'case_transform'
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class Json < Base
|
class Json < Base
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# {http://jsonapi.org/format/ JSON API specification}
|
# {http://jsonapi.org/format/ JSON API specification}
|
||||||
# rubocop:disable Style/AsciiComments
|
# rubocop:disable Style/AsciiComments
|
||||||
# TODO: implement!
|
# TODO: implement!
|
||||||
@ -22,14 +24,16 @@ module ActiveModelSerializers
|
|||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi < Base
|
class JsonApi < Base
|
||||||
extend ActiveSupport::Autoload
|
extend ActiveSupport::Autoload
|
||||||
|
eager_autoload do
|
||||||
autoload :Jsonapi
|
autoload :Jsonapi
|
||||||
autoload :ResourceIdentifier
|
autoload :ResourceIdentifier
|
||||||
autoload :Relationship
|
|
||||||
autoload :Link
|
autoload :Link
|
||||||
autoload :PaginationLinks
|
autoload :PaginationLinks
|
||||||
autoload :Meta
|
autoload :Meta
|
||||||
autoload :Error
|
autoload :Error
|
||||||
autoload :Deserialization
|
autoload :Deserialization
|
||||||
|
autoload :Relationship
|
||||||
|
end
|
||||||
|
|
||||||
def self.default_key_transform
|
def self.default_key_transform
|
||||||
:dash
|
:dash
|
||||||
@ -480,7 +484,8 @@ module ActiveModelSerializers
|
|||||||
# }.reject! {|_,v| v.nil? }
|
# }.reject! {|_,v| v.nil? }
|
||||||
def links_for(serializer)
|
def links_for(serializer)
|
||||||
serializer._links.each_with_object({}) do |(name, value), hash|
|
serializer._links.each_with_object({}) do |(name, value), hash|
|
||||||
result = Link.new(serializer, value).as_json
|
next if value.excluded?(serializer)
|
||||||
|
result = Link.new(serializer, value.block).as_json
|
||||||
hash[name] = result if result
|
hash[name] = result if result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi
|
class JsonApi
|
||||||
@ -189,7 +191,7 @@ module ActiveModelSerializers
|
|||||||
|
|
||||||
polymorphic = (options[:polymorphic] || []).include?(assoc_name.to_sym)
|
polymorphic = (options[:polymorphic] || []).include?(assoc_name.to_sym)
|
||||||
if polymorphic
|
if polymorphic
|
||||||
hash["#{prefix_key}_type".to_sym] = assoc_data.present? ? assoc_data['type'] : nil
|
hash["#{prefix_key}_type".to_sym] = assoc_data.present? ? assoc_data['type'].classify : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
hash
|
hash
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi < Base
|
class JsonApi < Base
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi < Base
|
class JsonApi < Base
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi
|
class JsonApi
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi
|
class JsonApi
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi < Base
|
class JsonApi < Base
|
||||||
@ -20,12 +22,13 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def as_json
|
def as_json
|
||||||
per_page = collection.try(:per_page) || collection.try(:limit_value) || collection.size
|
{
|
||||||
pages_from.each_with_object({}) do |(key, value), hash|
|
self: location_url,
|
||||||
params = query_parameters.merge(page: { number: value, size: per_page }).to_query
|
first: first_page_url,
|
||||||
|
prev: prev_page_url,
|
||||||
hash[key] = "#{url(adapter_options)}?#{params}"
|
next: next_page_url,
|
||||||
end
|
last: last_page_url
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
@ -34,25 +37,39 @@ module ActiveModelSerializers
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def pages_from
|
def location_url
|
||||||
return {} if collection.total_pages <= FIRST_PAGE
|
url_for_page(collection.current_page)
|
||||||
|
|
||||||
{}.tap do |pages|
|
|
||||||
pages[:self] = collection.current_page
|
|
||||||
|
|
||||||
unless collection.current_page == FIRST_PAGE
|
|
||||||
pages[:first] = FIRST_PAGE
|
|
||||||
pages[:prev] = collection.current_page - FIRST_PAGE
|
|
||||||
end
|
end
|
||||||
|
|
||||||
unless collection.current_page == collection.total_pages
|
def first_page_url
|
||||||
pages[:next] = collection.current_page + FIRST_PAGE
|
url_for_page(1)
|
||||||
pages[:last] = collection.total_pages
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def last_page_url
|
||||||
|
if collection.total_pages == 0
|
||||||
|
url_for_page(FIRST_PAGE)
|
||||||
|
else
|
||||||
|
url_for_page(collection.total_pages)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def url(options)
|
def prev_page_url
|
||||||
|
return nil if collection.current_page == FIRST_PAGE
|
||||||
|
url_for_page(collection.current_page - FIRST_PAGE)
|
||||||
|
end
|
||||||
|
|
||||||
|
def next_page_url
|
||||||
|
return nil if collection.total_pages == 0 || collection.current_page == collection.total_pages
|
||||||
|
url_for_page(collection.next_page)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url_for_page(number)
|
||||||
|
params = query_parameters.dup
|
||||||
|
params[:page] = { size: per_page, number: number }
|
||||||
|
"#{url(adapter_options)}?#{params.to_query}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def url(options = {})
|
||||||
@url ||= options.fetch(:links, {}).fetch(:self, nil) || request_url
|
@url ||= options.fetch(:links, {}).fetch(:self, nil) || request_url
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -63,6 +80,10 @@ module ActiveModelSerializers
|
|||||||
def query_parameters
|
def query_parameters
|
||||||
@query_parameters ||= context.query_parameters
|
@query_parameters ||= context.query_parameters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def per_page
|
||||||
|
@per_page ||= collection.try(:per_page) || collection.try(:limit_value) || collection.size
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi
|
class JsonApi
|
||||||
@ -43,10 +45,16 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def data_for_one(association)
|
def data_for_one(association)
|
||||||
if association.belongs_to? &&
|
if belongs_to_id_on_self?(association)
|
||||||
parent_serializer.object.respond_to?(association.reflection.foreign_key)
|
id = parent_serializer.read_attribute_for_serialization(association.reflection.foreign_key)
|
||||||
id = parent_serializer.object.send(association.reflection.foreign_key)
|
type =
|
||||||
type = association.reflection.type.to_s
|
if association.polymorphic?
|
||||||
|
# We can't infer resource type for polymorphic relationships from the serializer.
|
||||||
|
# We can ONLY know a polymorphic resource type by inspecting each resource.
|
||||||
|
association.lazy_association.serializer.json_key
|
||||||
|
else
|
||||||
|
association.reflection.type.to_s
|
||||||
|
end
|
||||||
ResourceIdentifier.for_type_with_id(type, id, serializable_resource_options)
|
ResourceIdentifier.for_type_with_id(type, id, serializable_resource_options)
|
||||||
else
|
else
|
||||||
# TODO(BF): Process relationship without evaluating lazy_association
|
# TODO(BF): Process relationship without evaluating lazy_association
|
||||||
@ -86,6 +94,12 @@ module ActiveModelSerializers
|
|||||||
meta = association.meta
|
meta = association.meta
|
||||||
meta.respond_to?(:call) ? parent_serializer.instance_eval(&meta) : meta
|
meta.respond_to?(:call) ? parent_serializer.instance_eval(&meta) : meta
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def belongs_to_id_on_self?(association)
|
||||||
|
parent_serializer.config.jsonapi_use_foreign_key_on_belongs_to_relationship &&
|
||||||
|
association.belongs_to? &&
|
||||||
|
parent_serializer.object.respond_to?(association.reflection.foreign_key)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,33 +1,37 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi
|
class JsonApi
|
||||||
class ResourceIdentifier
|
class ResourceIdentifier
|
||||||
def self.type_for(class_name, serializer_type = nil, transform_options = {})
|
def self.type_for(serializer, serializer_type = nil, transform_options = {})
|
||||||
if serializer_type
|
raw_type = serializer_type ? serializer_type : raw_type_from_serializer_object(serializer.object)
|
||||||
raw_type = serializer_type
|
|
||||||
else
|
|
||||||
inflection =
|
|
||||||
if ActiveModelSerializers.config.jsonapi_resource_type == :singular
|
|
||||||
:singularize
|
|
||||||
else
|
|
||||||
:pluralize
|
|
||||||
end
|
|
||||||
|
|
||||||
raw_type = class_name.underscore
|
|
||||||
raw_type = ActiveSupport::Inflector.public_send(inflection, raw_type)
|
|
||||||
raw_type
|
|
||||||
.gsub!('/'.freeze, ActiveModelSerializers.config.jsonapi_namespace_separator)
|
|
||||||
raw_type
|
|
||||||
end
|
|
||||||
JsonApi.send(:transform_key_casing!, raw_type, transform_options)
|
JsonApi.send(:transform_key_casing!, raw_type, transform_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.for_type_with_id(type, id, options)
|
def self.for_type_with_id(type, id, options)
|
||||||
return nil if id.blank?
|
type = inflect_type(type)
|
||||||
{
|
type = type_for(:no_class_needed, type, options)
|
||||||
id: id.to_s,
|
if id.blank?
|
||||||
type: type_for(:no_class_needed, type, options)
|
{ type: type }
|
||||||
}
|
else
|
||||||
|
{ id: id.to_s, type: type }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.raw_type_from_serializer_object(object)
|
||||||
|
class_name = object.class.name # should use model_name
|
||||||
|
raw_type = class_name.underscore
|
||||||
|
raw_type = inflect_type(raw_type)
|
||||||
|
raw_type
|
||||||
|
.gsub!('/'.freeze, ActiveModelSerializers.config.jsonapi_namespace_separator)
|
||||||
|
raw_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.inflect_type(type)
|
||||||
|
singularize = ActiveModelSerializers.config.jsonapi_resource_type == :singular
|
||||||
|
inflection = singularize ? :singularize : :pluralize
|
||||||
|
ActiveSupport::Inflector.public_send(inflection, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
# {http://jsonapi.org/format/#document-resource-identifier-objects Resource Identifier Objects}
|
# {http://jsonapi.org/format/#document-resource-identifier-objects Resource Identifier Objects}
|
||||||
@ -37,8 +41,11 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def as_json
|
def as_json
|
||||||
return nil if id.blank?
|
if id.blank?
|
||||||
{ id: id, type: type }
|
{ type: type }
|
||||||
|
else
|
||||||
|
{ id: id.to_s, type: type }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
@ -48,7 +55,8 @@ module ActiveModelSerializers
|
|||||||
private
|
private
|
||||||
|
|
||||||
def type_for(serializer, transform_options)
|
def type_for(serializer, transform_options)
|
||||||
self.class.type_for(serializer.object.class.name, serializer._type, transform_options)
|
serializer_type = serializer._type
|
||||||
|
self.class.type_for(serializer, serializer_type, transform_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def id_for(serializer)
|
def id_for(serializer)
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
class Null < Base
|
class Null < Base
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Adapted from
|
# Adapted from
|
||||||
# https://github.com/rails/rails/blob/7f18ea14c8/activejob/lib/active_job/callbacks.rb
|
# https://github.com/rails/rails/blob/7f18ea14c8/activejob/lib/active_job/callbacks.rb
|
||||||
require 'active_support/callbacks'
|
require 'active_support/callbacks'
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
##
|
##
|
||||||
# Provides a single method +deprecate+ to be used to declare when
|
# Provides a single method +deprecate+ to be used to declare when
|
||||||
# something is going away.
|
# something is going away.
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Deserialization
|
module Deserialization
|
||||||
module_function
|
module_function
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module JsonPointer
|
module JsonPointer
|
||||||
module_function
|
module_function
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
##
|
##
|
||||||
# ActiveModelSerializers::Logging
|
# ActiveModelSerializers::Logging
|
||||||
#
|
#
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module LookupChain
|
module LookupChain
|
||||||
# Standard appending of Serializer to the resource name.
|
# Standard appending of Serializer to the resource name.
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# ActiveModelSerializers::Model is a convenient superclass for making your models
|
# ActiveModelSerializers::Model is a convenient superclass for making your models
|
||||||
# from Plain-Old Ruby Objects (PORO). It also serves as a reference implementation
|
# from Plain-Old Ruby Objects (PORO). It also serves as a reference implementation
|
||||||
# that satisfies ActiveModel::Serializer::Lint::Tests.
|
# that satisfies ActiveModel::Serializer::Lint::Tests.
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails/railtie'
|
require 'rails/railtie'
|
||||||
require 'action_controller'
|
require 'action_controller'
|
||||||
require 'action_controller/railtie'
|
require 'action_controller/railtie'
|
||||||
@ -5,6 +7,8 @@ require 'action_controller/serialization'
|
|||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
class Railtie < Rails::Railtie
|
class Railtie < Rails::Railtie
|
||||||
|
config.eager_load_namespaces << ActiveModelSerializers
|
||||||
|
|
||||||
config.to_prepare do
|
config.to_prepare do
|
||||||
ActiveModel::Serializer.serializers_cache.clear
|
ActiveModel::Serializer.serializers_cache.clear
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Based on discussion in https://github.com/rails/rails/pull/23712#issuecomment-184977238,
|
# Based on discussion in https://github.com/rails/rails/pull/23712#issuecomment-184977238,
|
||||||
# the JSON API media type will have its own format/renderer.
|
# the JSON API media type will have its own format/renderer.
|
||||||
#
|
#
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'set'
|
require 'set'
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
@ -14,8 +16,8 @@ module ActiveModelSerializers
|
|||||||
# @return the serializable_resource, ready for #as_json/#to_json/#serializable_hash.
|
# @return the serializable_resource, ready for #as_json/#to_json/#serializable_hash.
|
||||||
def initialize(resource, options = {})
|
def initialize(resource, options = {})
|
||||||
@resource = resource
|
@resource = resource
|
||||||
@adapter_opts, @serializer_opts =
|
@adapter_opts = options.select { |k, _| ADAPTER_OPTION_KEYS.include? k }
|
||||||
options.partition { |k, _| ADAPTER_OPTION_KEYS.include? k }.map { |h| Hash[h] }
|
@serializer_opts = options.reject { |k, _| ADAPTER_OPTION_KEYS.include? k }
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialization_scope=(scope)
|
def serialization_scope=(scope)
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'active_support/core_ext/array/extract_options'
|
require 'active_support/core_ext/array/extract_options'
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
class SerializationContext
|
class SerializationContext
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Test
|
module Test
|
||||||
extend ActiveSupport::Autoload
|
extend ActiveSupport::Autoload
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Test
|
module Test
|
||||||
module Schema
|
module Schema
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'set'
|
require 'set'
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Test
|
module Test
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails/generators'
|
require 'rails/generators'
|
||||||
require 'rails/generators/rails/resource/resource_generator'
|
require 'rails/generators/rails/resource/resource_generator'
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Rails
|
module Rails
|
||||||
module Generators
|
module Generators
|
||||||
class SerializerGenerator < NamedBase
|
class SerializerGenerator < NamedBase
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# To add Grape support, require 'grape/active_model_serializers' in the base of your Grape endpoints
|
# To add Grape support, require 'grape/active_model_serializers' in the base of your Grape endpoints
|
||||||
# Then add 'include Grape::ActiveModelSerializers' to enable the formatter and helpers
|
# Then add 'include Grape::ActiveModelSerializers' to enable the formatter and helpers
|
||||||
require 'active_model_serializers'
|
require 'active_model_serializers'
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# A Grape response formatter that can be used as 'formatter :json, Grape::Formatters::ActiveModelSerializers'
|
# A Grape response formatter that can be used as 'formatter :json, Grape::Formatters::ActiveModelSerializers'
|
||||||
#
|
#
|
||||||
# Serializer options can be passed as a hash from your Grape endpoint using env[:active_model_serializer_options],
|
# Serializer options can be passed as a hash from your Grape endpoint using env[:active_model_serializer_options],
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Helpers can be included in your Grape endpoint as: helpers Grape::Helpers::ActiveModelSerializers
|
# Helpers can be included in your Grape endpoint as: helpers Grape::Helpers::ActiveModelSerializers
|
||||||
|
|
||||||
module Grape
|
module Grape
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'rubocop'
|
require 'rubocop'
|
||||||
require 'rubocop/rake_task'
|
require 'rubocop/rake_task'
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
@ -45,7 +47,7 @@ module ActionController
|
|||||||
response = JSON.parse(@response.body)
|
response = JSON.parse(@response.body)
|
||||||
expected = {
|
expected = {
|
||||||
'restriction_for_id' => '67',
|
'restriction_for_id' => '67',
|
||||||
'restriction_for_type' => 'discounts',
|
'restriction_for_type' => 'Discount',
|
||||||
'restricted_to_id' => nil,
|
'restricted_to_id' => nil,
|
||||||
'restricted_to_type' => nil
|
'restricted_to_type' => nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
require 'will_paginate/array'
|
require 'will_paginate/array'
|
||||||
require 'kaminari'
|
require 'kaminari'
|
||||||
@ -58,8 +60,10 @@ module ActionController
|
|||||||
assert_equal expected_links, response['links']
|
assert_equal expected_links, response['links']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_only_last_and_next_pagination_links
|
def test_render_only_first_last_and_next_pagination_links
|
||||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||||
|
'first' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2",
|
||||||
|
'prev' => nil,
|
||||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2",
|
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2",
|
||||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2" }
|
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2" }
|
||||||
get :render_pagination_using_will_paginate, params: { page: { number: 1, size: 2 } }
|
get :render_pagination_using_will_paginate, params: { page: { number: 1, size: 2 } }
|
||||||
@ -78,17 +82,21 @@ module ActionController
|
|||||||
assert_equal expected_links, response['links']
|
assert_equal expected_links, response['links']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_only_prev_and_first_pagination_links
|
def test_render_only_prev_first_and_last_pagination_links
|
||||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1",
|
||||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1",
|
||||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1" }
|
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1",
|
||||||
|
'next' => nil,
|
||||||
|
'last' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1" }
|
||||||
get :render_pagination_using_kaminari, params: { page: { number: 3, size: 1 } }
|
get :render_pagination_using_kaminari, params: { page: { number: 3, size: 1 } }
|
||||||
response = JSON.parse(@response.body)
|
response = JSON.parse(@response.body)
|
||||||
assert_equal expected_links, response['links']
|
assert_equal expected_links, response['links']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_only_last_and_next_pagination_links_with_additional_params
|
def test_render_only_first_last_and_next_pagination_links_with_additional_params
|
||||||
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2&teste=additional",
|
expected_links = { 'self' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2&teste=additional",
|
||||||
|
'first' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=2&teste=additional",
|
||||||
|
'prev' => nil,
|
||||||
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional",
|
'next' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional",
|
||||||
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional" }
|
'last' => "#{WILL_PAGINATE_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=2&teste=additional" }
|
||||||
get :render_pagination_using_will_paginate, params: { page: { number: 1, size: 2 }, teste: 'additional' }
|
get :render_pagination_using_will_paginate, params: { page: { number: 1, size: 2 }, teste: 'additional' }
|
||||||
@ -96,10 +104,12 @@ module ActionController
|
|||||||
assert_equal expected_links, response['links']
|
assert_equal expected_links, response['links']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_only_prev_and_first_pagination_links_with_additional_params
|
def test_render_only_prev_first_and_last_pagination_links_with_additional_params
|
||||||
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1&teste=additional",
|
expected_links = { 'self' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1&teste=additional",
|
||||||
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1&teste=additional",
|
'first' => "#{KAMINARI_URI}?page%5Bnumber%5D=1&page%5Bsize%5D=1&teste=additional",
|
||||||
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1&teste=additional" }
|
'prev' => "#{KAMINARI_URI}?page%5Bnumber%5D=2&page%5Bsize%5D=1&teste=additional",
|
||||||
|
'next' => nil,
|
||||||
|
'last' => "#{KAMINARI_URI}?page%5Bnumber%5D=3&page%5Bsize%5D=1&teste=additional" }
|
||||||
get :render_pagination_using_kaminari, params: { page: { number: 3, size: 1 }, teste: 'additional' }
|
get :render_pagination_using_kaminari, params: { page: { number: 3, size: 1 }, teste: 'additional' }
|
||||||
response = JSON.parse(@response.body)
|
response = JSON.parse(@response.body)
|
||||||
assert_equal expected_links, response['links']
|
assert_equal expected_links, response['links']
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module SerializationScopeTesting
|
module SerializationScopeTesting
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
@ -457,13 +459,19 @@ module ActionController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_render_event_is_emitted
|
def test_render_event_is_emitted
|
||||||
subscriber = ::ActiveSupport::Notifications.subscribe('render.active_model_serializers') do |name|
|
subscriber = ::ActiveSupport::Notifications.subscribe('render.active_model_serializers') do |subscribed_event|
|
||||||
@name = name
|
@subscribed_event = subscribed_event
|
||||||
end
|
end
|
||||||
|
|
||||||
get :render_using_implicit_serializer
|
get :render_using_implicit_serializer
|
||||||
|
|
||||||
assert_equal 'render.active_model_serializers', @name
|
subscribed_event_name =
|
||||||
|
if @subscribed_event.is_a?(String)
|
||||||
|
@subscribed_event
|
||||||
|
else
|
||||||
|
@subscribed_event.name # is a ActiveSupport::Notifications::Event
|
||||||
|
end
|
||||||
|
assert_equal 'render.active_model_serializers', subscribed_event_name
|
||||||
ensure
|
ensure
|
||||||
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
|
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Execute this test in isolation
|
# Execute this test in isolation
|
||||||
require 'support/isolated_unit'
|
require 'support/isolated_unit'
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'support/isolated_unit'
|
require 'support/isolated_unit'
|
||||||
require 'minitest/mock'
|
require 'minitest/mock'
|
||||||
require 'action_dispatch'
|
require 'action_dispatch'
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Execute this test in isolation
|
# Execute this test in isolation
|
||||||
require 'support/isolated_unit'
|
require 'support/isolated_unit'
|
||||||
require 'minitest/mock'
|
require 'minitest/mock'
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ActiveRecordTest < ActiveSupport::TestCase
|
class ActiveRecordTest < ActiveSupport::TestCase
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user