mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Code cleanup (#2369)
* Lint travis.yml on https://config.travis-ci.com/explore
* Replace deprecated 'thread_safe' with 'concurrent-ruby' alternative
'thread_safe' gem is now deprecated and merged into 'concurrent-ruby'.
Ref: 52e5f373a9 (diff-42d5a45da331eaa07d2b315bd3c9e738)
* Fix deprecation warning for Ruby 2.7
https://bugs.ruby-lang.org/issues/15539
* Remove a TODO tag that is already resolved
This commit is contained in:
parent
6b093c965f
commit
64c7fee7a8
18
.travis.yml
18
.travis.yml
@ -1,7 +1,7 @@
|
|||||||
language: ruby
|
language: ruby
|
||||||
sudo: false
|
os: linux
|
||||||
|
|
||||||
ruby_supported_versions:
|
_ruby_supported_versions:
|
||||||
- &ruby_2_1 2.1.10
|
- &ruby_2_1 2.1.10
|
||||||
- &ruby_2_2 2.2.10
|
- &ruby_2_2 2.2.10
|
||||||
- &ruby_2_3 2.3.8
|
- &ruby_2_3 2.3.8
|
||||||
@ -10,15 +10,15 @@ ruby_supported_versions:
|
|||||||
- &ruby_2_6 2.6.5
|
- &ruby_2_6 2.6.5
|
||||||
- &ruby_head ruby-head
|
- &ruby_head ruby-head
|
||||||
|
|
||||||
jruby_supported_versions:
|
_jruby_supported_versions:
|
||||||
- &jruby_9_1 jruby-9.1.17.0
|
- &jruby_9_1 jruby-9.1.17.0
|
||||||
- &jruby_9_2 jruby-9.2.8.0
|
- &jruby_9_2 jruby-9.2.8.0
|
||||||
- &jruby_head jruby-head
|
- &jruby_head jruby-head
|
||||||
|
|
||||||
jdk_supported_versions:
|
_jdk_supported_versions:
|
||||||
- &jdk_8 openjdk8
|
- &jdk_8 openjdk8
|
||||||
|
|
||||||
rails_supported_versions:
|
_rails_supported_versions:
|
||||||
- &rails_4_1 RAILS_VERSION=4.1
|
- &rails_4_1 RAILS_VERSION=4.1
|
||||||
- &rails_4_1_jruby RAILS_VERSION=4.1 JRUBY_OPTS='--dev -J-Xmx1024M --debug'
|
- &rails_4_1_jruby RAILS_VERSION=4.1 JRUBY_OPTS='--dev -J-Xmx1024M --debug'
|
||||||
- &rails_4_2 RAILS_VERSION=4.2
|
- &rails_4_2 RAILS_VERSION=4.2
|
||||||
@ -41,7 +41,7 @@ cache:
|
|||||||
before_install:
|
before_install:
|
||||||
- "travis_retry gem update --system 2.7.9"
|
- "travis_retry gem update --system 2.7.9"
|
||||||
- "travis_retry gem install bundler -v '1.17.3'"
|
- "travis_retry gem install bundler -v '1.17.3'"
|
||||||
install: BUNDLER_VERSION=1.17.3 bundle install --path=vendor/bundle --retry=3 --jobs=3
|
install: bundle install --path=vendor/bundle --retry=3 --jobs=3
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- bundle exec rake ci
|
- bundle exec rake ci
|
||||||
@ -49,7 +49,9 @@ after_success:
|
|||||||
- codeclimate-test-reporter
|
- codeclimate-test-reporter
|
||||||
|
|
||||||
env:
|
env:
|
||||||
matrix:
|
global:
|
||||||
|
- BUNDLER_VERSION=1.17.3
|
||||||
|
jobs:
|
||||||
- *rails_4_1
|
- *rails_4_1
|
||||||
- *rails_4_2
|
- *rails_4_2
|
||||||
- *rails_5_0
|
- *rails_5_0
|
||||||
@ -70,7 +72,7 @@ rvm:
|
|||||||
branches:
|
branches:
|
||||||
only: 0-10-stable
|
only: 0-10-stable
|
||||||
|
|
||||||
matrix:
|
jobs:
|
||||||
include:
|
include:
|
||||||
- { rvm: *jruby_9_1, jdk: *jdk_8, env: *rails_4_1_jruby }
|
- { rvm: *jruby_9_1, jdk: *jdk_8, env: *rails_4_1_jruby }
|
||||||
- { rvm: *jruby_9_1, jdk: *jdk_8, env: *rails_4_2_jruby }
|
- { rvm: *jruby_9_1, jdk: *jdk_8, env: *rails_4_2_jruby }
|
||||||
|
|||||||
@ -59,5 +59,5 @@ Gem::Specification.new do |spec|
|
|||||||
spec.add_development_dependency 'timecop', '~> 0.7'
|
spec.add_development_dependency 'timecop', '~> 0.7'
|
||||||
spec.add_development_dependency 'grape', ['>= 0.13', '< 0.19.1']
|
spec.add_development_dependency 'grape', ['>= 0.13', '< 0.19.1']
|
||||||
spec.add_development_dependency 'json_schema'
|
spec.add_development_dependency 'json_schema'
|
||||||
spec.add_development_dependency 'rake', ['>= 10.0', '< 12.0']
|
spec.add_development_dependency 'rake', ['>= 10.0', '< 13.0']
|
||||||
end
|
end
|
||||||
|
|||||||
@ -73,7 +73,7 @@ module ActiveModel
|
|||||||
# Used to cache serializer name => serializer class
|
# Used to cache serializer name => serializer class
|
||||||
# when looked up by Serializer.get_serializer_for.
|
# when looked up by Serializer.get_serializer_for.
|
||||||
def self.serializers_cache
|
def self.serializers_cache
|
||||||
@serializers_cache ||= ThreadSafe::Cache.new
|
@serializers_cache ||= Concurrent::Map.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
|
|||||||
@ -87,8 +87,8 @@ module ActiveModel
|
|||||||
# meta ids: ids
|
# meta ids: ids
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
def link(name, value = nil)
|
def link(name, value = nil, &block)
|
||||||
options[:links][name] = block_given? ? Proc.new : value
|
options[:links][name] = block_given? ? block : value
|
||||||
:nil
|
:nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -102,8 +102,8 @@ module ActiveModel
|
|||||||
# href object.blog.id.to_s
|
# href object.blog.id.to_s
|
||||||
# meta(id: object.blog.id)
|
# meta(id: object.blog.id)
|
||||||
# end
|
# end
|
||||||
def meta(value = nil)
|
def meta(value = nil, &block)
|
||||||
options[:meta] = block_given? ? Proc.new : value
|
options[:meta] = block_given? ? block : value
|
||||||
:nil
|
:nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -35,12 +35,11 @@ module ActiveModel
|
|||||||
class BookSerializer < ActiveModel::Serializer
|
class BookSerializer < ActiveModel::Serializer
|
||||||
attributes :title, :author_name
|
attributes :title, :author_name
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'resource without a namespace' do
|
test 'resource without a namespace' do
|
||||||
book = Book.new(title: 'A Post', author_name: 'hello')
|
book = Book.new(title: 'A Post', author_name: 'hello')
|
||||||
|
|
||||||
# TODO: this should be able to pull up this serializer without explicitly specifying the serializer
|
result = ActiveModelSerializers::SerializableResource.new(book).serializable_hash
|
||||||
# currently, with no options, it still uses the Api::V3 serializer
|
|
||||||
result = ActiveModelSerializers::SerializableResource.new(book, serializer: BookSerializer).serializable_hash
|
|
||||||
|
|
||||||
expected = { title: 'A Post', author_name: 'hello' }
|
expected = { title: 'A Post', author_name: 'hello' }
|
||||||
assert_equal expected, result
|
assert_equal expected, result
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user