mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
commit
f8d2aabf38
19
.rubocop.yml
19
.rubocop.yml
@ -4,15 +4,20 @@ AllCops:
|
|||||||
Exclude:
|
Exclude:
|
||||||
- config/initializers/forbidden_yaml.rb
|
- config/initializers/forbidden_yaml.rb
|
||||||
- !ruby/regexp /(vendor|bundle|bin|db|tmp)\/.*/
|
- !ruby/regexp /(vendor|bundle|bin|db|tmp)\/.*/
|
||||||
RunRailsCops: true
|
|
||||||
DisplayCopNames: true
|
DisplayCopNames: true
|
||||||
DisplayStyleGuide: true
|
DisplayStyleGuide: true
|
||||||
|
|
||||||
|
Rails:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Lint/NestedMethodDefinition:
|
Lint/NestedMethodDefinition:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
Exclude:
|
Exclude:
|
||||||
- test/action_controller/serialization_test.rb
|
- test/action_controller/serialization_test.rb
|
||||||
|
|
||||||
|
Style/Alias:
|
||||||
|
EnforcedStyle: prefer_alias
|
||||||
|
|
||||||
Style/StringLiterals:
|
Style/StringLiterals:
|
||||||
EnforcedStyle: single_quotes
|
EnforcedStyle: single_quotes
|
||||||
|
|
||||||
@ -59,6 +64,18 @@ Style/BlockDelimiters:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
EnforcedStyle: line_count_based
|
EnforcedStyle: line_count_based
|
||||||
|
|
||||||
|
Style/SignalException:
|
||||||
|
EnforcedStyle: semantic
|
||||||
|
|
||||||
|
Style/TrailingCommaInLiteral:
|
||||||
|
EnforcedStyleForMultiline: no_comma
|
||||||
|
|
||||||
|
Style/ConditionalAssignment:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/DotPosition:
|
||||||
|
EnforcedStyle: leading
|
||||||
|
|
||||||
########## test_helper.rb sanity
|
########## test_helper.rb sanity
|
||||||
Style/EndBlock:
|
Style/EndBlock:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# This configuration was generated by
|
# This configuration was generated by
|
||||||
# `rubocop --auto-gen-config`
|
# `rubocop --auto-gen-config`
|
||||||
# on 2015-09-20 17:56:22 -0500 using RuboCop version 0.34.0.
|
# on 2016-03-08 22:29:52 +0100 using RuboCop version 0.37.2.
|
||||||
# The point is for the user to remove these configuration records
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the offenses are removed from the code base.
|
# one by one as the offenses are removed from the code base.
|
||||||
# Note that changes in the inspected code, or installation of new
|
# Note that changes in the inspected code, or installation of new
|
||||||
@ -13,49 +13,31 @@ Lint/HandleExceptions:
|
|||||||
|
|
||||||
# Offense count: 2
|
# Offense count: 2
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
Lint/UnusedBlockArgument:
|
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
||||||
Exclude:
|
|
||||||
- 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'
|
|
||||||
|
|
||||||
# Offense count: 7
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Lint/UnusedMethodArgument:
|
Lint/UnusedMethodArgument:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/active_model/serializer/adapter/null.rb'
|
|
||||||
- 'lib/active_model/serializer/pass_through_serializer.rb'
|
|
||||||
- 'test/fixtures/poro.rb'
|
|
||||||
- 'test/lint_test.rb'
|
- 'test/lint_test.rb'
|
||||||
|
|
||||||
# Offense count: 2
|
|
||||||
Lint/UselessAssignment:
|
|
||||||
Exclude:
|
|
||||||
- 'bench/perf.rb'
|
|
||||||
- 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
||||||
Rails/Date:
|
|
||||||
Exclude:
|
|
||||||
- 'test/fixtures/poro.rb'
|
|
||||||
|
|
||||||
# Offense count: 4
|
# Offense count: 4
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
|
# SupportedStyles: strict, flexible
|
||||||
Rails/TimeZone:
|
Rails/TimeZone:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'test/action_controller/serialization_test.rb'
|
- 'test/action_controller/serialization_test.rb'
|
||||||
- 'test/fixtures/poro.rb'
|
|
||||||
- 'test/serializers/cache_test.rb'
|
- 'test/serializers/cache_test.rb'
|
||||||
|
|
||||||
# Offense count: 16
|
# Offense count: 16
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
||||||
|
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
||||||
Style/AlignHash:
|
Style/AlignHash:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'test/action_controller/json_api/pagination_test.rb'
|
- 'test/action_controller/json_api/pagination_test.rb'
|
||||||
|
|
||||||
# Offense count: 25
|
# Offense count: 27
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
|
# SupportedStyles: braces, no_braces, context_dependent
|
||||||
Style/BracesAroundHashParameters:
|
Style/BracesAroundHashParameters:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'test/action_controller/adapter_selector_test.rb'
|
- 'test/action_controller/adapter_selector_test.rb'
|
||||||
@ -67,17 +49,16 @@ Style/BracesAroundHashParameters:
|
|||||||
- 'test/collection_serializer_test.rb'
|
- 'test/collection_serializer_test.rb'
|
||||||
- 'test/serializable_resource_test.rb'
|
- 'test/serializable_resource_test.rb'
|
||||||
- 'test/serializers/associations_test.rb'
|
- 'test/serializers/associations_test.rb'
|
||||||
- 'test/serializers/attribute_test.rb'
|
|
||||||
- 'test/serializers/attributes_test.rb'
|
- 'test/serializers/attributes_test.rb'
|
||||||
- 'test/serializers/fieldset_test.rb'
|
|
||||||
- 'test/serializers/root_test.rb'
|
- 'test/serializers/root_test.rb'
|
||||||
|
|
||||||
# Offense count: 174
|
# Offense count: 271
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
|
# SupportedStyles: nested, compact
|
||||||
Style/ClassAndModuleChildren:
|
Style/ClassAndModuleChildren:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 5
|
# Offense count: 6
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
Style/CommentIndentation:
|
Style/CommentIndentation:
|
||||||
Exclude:
|
Exclude:
|
||||||
@ -89,34 +70,29 @@ Style/DoubleNegation:
|
|||||||
- 'lib/active_model/serializable_resource.rb'
|
- 'lib/active_model/serializable_resource.rb'
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
Style/EachWithObject:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/active_model/serializer/fieldset.rb'
|
|
||||||
|
|
||||||
# Offense count: 2
|
|
||||||
# Configuration parameters: MinBodyLength.
|
# Configuration parameters: MinBodyLength.
|
||||||
Style/GuardClause:
|
Style/GuardClause:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/active_model/serializer.rb'
|
- 'lib/active_model/serializer.rb'
|
||||||
|
|
||||||
# Offense count: 12
|
# Offense count: 58
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
|
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
|
||||||
|
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
|
||||||
Style/HashSyntax:
|
Style/HashSyntax:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 9
|
# Offense count: 4
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
|
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
||||||
|
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
|
||||||
Style/IndentArray:
|
Style/IndentArray:
|
||||||
Exclude:
|
Enabled: false
|
||||||
- 'test/adapter/json/has_many_test.rb'
|
|
||||||
- 'test/adapter/json_api/json_api_test.rb'
|
|
||||||
- 'test/adapter/json_api/pagination_links_test.rb'
|
|
||||||
- 'test/adapter/json_test.rb'
|
|
||||||
|
|
||||||
# Offense count: 8
|
# Offense count: 10
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
||||||
|
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
||||||
Style/IndentHash:
|
Style/IndentHash:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
@ -129,12 +105,14 @@ Style/Lambda:
|
|||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
|
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
|
||||||
Style/MethodDefParentheses:
|
Style/MethodDefParentheses:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 3
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
||||||
|
# SupportedStyles: aligned, indented
|
||||||
Style/MultilineOperationIndentation:
|
Style/MultilineOperationIndentation:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
@ -146,45 +124,26 @@ Style/NegatedIf:
|
|||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
Style/NumericLiterals:
|
|
||||||
MinDigits: 7
|
|
||||||
|
|
||||||
# Offense count: 2
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Style/PerlBackrefs:
|
Style/PerlBackrefs:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'test/fixtures/poro.rb'
|
- 'test/fixtures/poro.rb'
|
||||||
- 'test/serializers/associations_test.rb'
|
|
||||||
|
|
||||||
# Offense count: 3
|
# Offense count: 3
|
||||||
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
|
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
|
||||||
|
# NamePrefix: is_, has_, have_
|
||||||
|
# NamePrefixBlacklist: is_, has_, have_
|
||||||
|
# NameWhitelist: is_a?
|
||||||
Style/PredicateName:
|
Style/PredicateName:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/active_model/serializer/associations.rb'
|
- 'lib/active_model/serializer/associations.rb'
|
||||||
- 'test/action_controller/json_api/linked_test.rb'
|
- 'test/action_controller/json_api/linked_test.rb'
|
||||||
|
|
||||||
# Offense count: 5
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
Style/RedundantSelf:
|
Style/RedundantSelf:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/active_model/serializer/associations.rb'
|
|
||||||
- 'test/fixtures/poro.rb'
|
- 'test/fixtures/poro.rb'
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: AllowAsExpressionSeparator.
|
|
||||||
Style/Semicolon:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/active_model/serializer/fieldset.rb'
|
|
||||||
|
|
||||||
# Offense count: 3
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
||||||
Style/SignalException:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/active_model/serializer/fieldset.rb'
|
|
||||||
- 'lib/active_model/serializer/pass_through_serializer.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: AllowIfMethodIsEmpty.
|
# Configuration parameters: AllowIfMethodIsEmpty.
|
||||||
@ -192,48 +151,17 @@ Style/SingleLineMethods:
|
|||||||
Exclude:
|
Exclude:
|
||||||
- 'test/serializers/serializer_for_test.rb'
|
- 'test/serializers/serializer_for_test.rb'
|
||||||
|
|
||||||
# Offense count: 2
|
# Offense count: 4
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
|
# SupportedStyles: single_quotes, double_quotes
|
||||||
Style/StringLiteralsInInterpolation:
|
Style/StringLiteralsInInterpolation:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
Style/StructInheritance:
|
|
||||||
Exclude:
|
|
||||||
- 'bench/perf.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: IgnoredMethods.
|
|
||||||
Style/SymbolProc:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/generators/serializer/serializer_generator.rb'
|
|
||||||
|
|
||||||
# Offense count: 8
|
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
|
# SupportedStyles: final_newline, final_blank_line
|
||||||
Style/TrailingBlankLines:
|
Style/TrailingBlankLines:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/active_model/serializer/pass_through_serializer.rb'
|
|
||||||
- 'lib/generators/serializer/serializer_generator.rb'
|
|
||||||
- 'test/adapter/fragment_cache_test.rb'
|
|
||||||
- 'test/adapter/json_api/json_api_test.rb'
|
|
||||||
- 'test/adapter/null_test.rb'
|
- 'test/adapter/null_test.rb'
|
||||||
- 'test/serializers/cache_test.rb'
|
|
||||||
- 'test/serializers/fieldset_test.rb'
|
|
||||||
|
|
||||||
# Offense count: 5
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
|
|
||||||
Style/TrailingComma:
|
|
||||||
Exclude:
|
|
||||||
- 'test/action_controller/adapter_selector_test.rb'
|
|
||||||
- 'test/action_controller/serialization_test.rb'
|
|
||||||
- 'test/adapter/json_api/belongs_to_test.rb'
|
|
||||||
- 'test/adapter/json_api/linked_test.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
Style/UnlessElse:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/active_model/serializer.rb'
|
|
||||||
|
|||||||
@ -31,6 +31,7 @@ Fixes:
|
|||||||
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
|
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
|
||||||
|
|
||||||
Misc:
|
Misc:
|
||||||
|
- [#1560](https://github.com/rails-api/active_model_serializers/pull/1560) Update rubocop and address its warnings. (@bf4 @groyoh)
|
||||||
- [#1545](https://github.com/rails-api/active_model_serializers/pull/1545) Document how to pass arbitrary options to the
|
- [#1545](https://github.com/rails-api/active_model_serializers/pull/1545) Document how to pass arbitrary options to the
|
||||||
serializer (@CodedBeardedSignedTaylor)
|
serializer (@CodedBeardedSignedTaylor)
|
||||||
- [#1496](https://github.com/rails-api/active_model_serializers/pull/1496) Run all branches against JRuby on CI (@nadavshatz)
|
- [#1496](https://github.com/rails-api/active_model_serializers/pull/1496) Run all branches against JRuby on CI (@nadavshatz)
|
||||||
|
|||||||
2
Gemfile
2
Gemfile
@ -44,5 +44,5 @@ group :test do
|
|||||||
end
|
end
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'rubocop', '~> 0.34.0', require: false
|
gem 'rubocop', '~> 0.36', require: false
|
||||||
end
|
end
|
||||||
|
|||||||
@ -33,7 +33,7 @@ module ActiveModel
|
|||||||
def adapter
|
def adapter
|
||||||
@adapter ||= ActiveModelSerializers::Adapter.create(serializer_instance, adapter_opts)
|
@adapter ||= ActiveModelSerializers::Adapter.create(serializer_instance, adapter_opts)
|
||||||
end
|
end
|
||||||
alias_method :adapter_instance, :adapter
|
alias adapter_instance adapter
|
||||||
|
|
||||||
def serializer_instance
|
def serializer_instance
|
||||||
@serializer_instance ||= serializer.new(resource, serializer_opts)
|
@serializer_instance ||= serializer.new(resource, serializer_opts)
|
||||||
@ -54,7 +54,7 @@ module ActiveModel
|
|||||||
@serializer
|
@serializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias_method :serializer_class, :serializer
|
alias serializer_class serializer
|
||||||
|
|
||||||
# True when no explicit adapter given, or explicit appear is truthy (non-nil)
|
# True when no explicit adapter given, or explicit appear is truthy (non-nil)
|
||||||
# False when explicit adapter is falsy (nil or false)
|
# False when explicit adapter is falsy (nil or false)
|
||||||
@ -63,7 +63,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def serializer?
|
def serializer?
|
||||||
use_adapter? && !!(serializer)
|
use_adapter? && !!serializer
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
@ -92,7 +92,7 @@ module ActiveModel
|
|||||||
self._cache_key = options.delete(:key)
|
self._cache_key = options.delete(:key)
|
||||||
self._cache_only = options.delete(:only)
|
self._cache_only = options.delete(:only)
|
||||||
self._cache_except = options.delete(:except)
|
self._cache_except = options.delete(:except)
|
||||||
self._cache_options = (options.empty?) ? nil : options
|
self._cache_options = options.empty? ? nil : options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -14,7 +14,7 @@ module ActiveModel
|
|||||||
serializer_context_class = options.fetch(:serializer_context_class, ActiveModel::Serializer)
|
serializer_context_class = options.fetch(:serializer_context_class, ActiveModel::Serializer)
|
||||||
serializer_class = options.fetch(:serializer) { serializer_context_class.serializer_for(resource) }
|
serializer_class = options.fetch(:serializer) { serializer_context_class.serializer_for(resource) }
|
||||||
|
|
||||||
if serializer_class.nil?
|
if serializer_class.nil? # rubocop:disable Style/GuardClause
|
||||||
fail NoSerializerError, "No serializer found for resource: #{resource.inspect}"
|
fail NoSerializerError, "No serializer found for resource: #{resource.inspect}"
|
||||||
else
|
else
|
||||||
serializer_class.new(resource, options.except(:serializer))
|
serializer_class.new(resource, options.except(:serializer))
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
VERSION = '0.10.0.rc4'
|
VERSION = '0.10.0.rc4'.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Adapter
|
module Adapter
|
||||||
UnknownAdapterError = Class.new(ArgumentError)
|
UnknownAdapterError = Class.new(ArgumentError)
|
||||||
ADAPTER_MAP = {}
|
ADAPTER_MAP = {} # rubocop:disable Style/MutableConstant
|
||||||
private_constant :ADAPTER_MAP if defined?(private_constant)
|
private_constant :ADAPTER_MAP if defined?(private_constant)
|
||||||
require 'active_model_serializers/adapter/fragment_cache'
|
require 'active_model_serializers/adapter/fragment_cache'
|
||||||
require 'active_model_serializers/adapter/cached_serializer'
|
require 'active_model_serializers/adapter/cached_serializer'
|
||||||
@ -49,7 +49,7 @@ module ActiveModelSerializers
|
|||||||
# 'Json' will both register as 'json'.
|
# 'Json' will both register as 'json'.
|
||||||
def register(name, klass = name)
|
def register(name, klass = name)
|
||||||
name = name.to_s.gsub(/\AActiveModelSerializers::Adapter::/, ''.freeze)
|
name = name.to_s.gsub(/\AActiveModelSerializers::Adapter::/, ''.freeze)
|
||||||
adapter_map.update(name.underscore => klass)
|
adapter_map[name.underscore] = klass
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@ module ActiveModelSerializers
|
|||||||
def object_cache_key
|
def object_cache_key
|
||||||
object_time_safe = @cached_serializer.object.updated_at
|
object_time_safe = @cached_serializer.object.updated_at
|
||||||
object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime)
|
object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime)
|
||||||
(@klass._cache_key) ? "#{@klass._cache_key}/#{@cached_serializer.object.id}-#{object_time_safe}" : @cached_serializer.object.cache_key
|
@klass._cache_key ? "#{@klass._cache_key}/#{@cached_serializer.object.id}-#{object_time_safe}" : @cached_serializer.object.cache_key
|
||||||
end
|
end
|
||||||
|
|
||||||
# find all cache_key for the collection_serializer
|
# find all cache_key for the collection_serializer
|
||||||
|
|||||||
@ -46,7 +46,7 @@ module ActiveModelSerializers
|
|||||||
# 3. Add non-cached attributes to non-cached Serializer
|
# 3. Add non-cached attributes to non-cached Serializer
|
||||||
def cached_attributes(klass, serializers)
|
def cached_attributes(klass, serializers)
|
||||||
attributes = serializer.class._attributes
|
attributes = serializer.class._attributes
|
||||||
cached_attributes = (klass._cache_only) ? klass._cache_only : attributes.reject { |attr| klass._cache_except.include?(attr) }
|
cached_attributes = klass._cache_only ? klass._cache_only : attributes.reject { |attr| klass._cache_except.include?(attr) }
|
||||||
non_cached_attributes = attributes - cached_attributes
|
non_cached_attributes = attributes - cached_attributes
|
||||||
|
|
||||||
cached_attributes.each do |attribute|
|
cached_attributes.each do |attribute|
|
||||||
|
|||||||
@ -188,7 +188,7 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
polymorphic = (options[:polymorphic] || []).include?(assoc_name.to_sym)
|
polymorphic = (options[:polymorphic] || []).include?(assoc_name.to_sym)
|
||||||
hash.merge!("#{prefix_key}_type".to_sym => assoc_data['type']) if polymorphic
|
hash["#{prefix_key}_type".to_sym] = assoc_data['type'] if polymorphic
|
||||||
|
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,7 +8,7 @@ module ActiveModelSerializers
|
|||||||
no_root_cache = cached_hash.delete_if { |key, _value| key == core_cached[0] }
|
no_root_cache = cached_hash.delete_if { |key, _value| key == core_cached[0] }
|
||||||
no_root_non_cache = non_cached_hash.delete_if { |key, _value| key == core_non_cached[0] }
|
no_root_non_cache = non_cached_hash.delete_if { |key, _value| key == core_non_cached[0] }
|
||||||
cached_resource = (core_cached[1]) ? core_cached[1].deep_merge(core_non_cached[1]) : core_non_cached[1]
|
cached_resource = (core_cached[1]) ? core_cached[1].deep_merge(core_non_cached[1]) : core_non_cached[1]
|
||||||
hash = (root) ? { root => cached_resource } : cached_resource
|
hash = root ? { root => cached_resource } : cached_resource
|
||||||
|
|
||||||
hash.deep_merge no_root_non_cache.deep_merge no_root_cache
|
hash.deep_merge no_root_non_cache.deep_merge no_root_cache
|
||||||
end
|
end
|
||||||
|
|||||||
@ -38,8 +38,7 @@ module ActiveModelSerializers
|
|||||||
def data_for(serializer, options)
|
def data_for(serializer, options)
|
||||||
if serializer.respond_to?(:each)
|
if serializer.respond_to?(:each)
|
||||||
serializer.map { |s| ResourceIdentifier.new(s).as_json }
|
serializer.map { |s| ResourceIdentifier.new(s).as_json }
|
||||||
else
|
elsif options[:virtual_value]
|
||||||
if options[:virtual_value]
|
|
||||||
options[:virtual_value]
|
options[:virtual_value]
|
||||||
elsif serializer && serializer.object
|
elsif serializer && serializer.object
|
||||||
ResourceIdentifier.new(serializer).as_json
|
ResourceIdentifier.new(serializer).as_json
|
||||||
@ -49,4 +48,3 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ module ActiveModelSerializers
|
|||||||
alias_method old, name
|
alias_method old, name
|
||||||
class_eval do
|
class_eval do
|
||||||
define_method(name) do |*args, &block|
|
define_method(name) do |*args, &block|
|
||||||
target = self.is_a?(Module) ? "#{self}." : "#{self.class}#"
|
target = is_a?(Module) ? "#{self}." : "#{self.class}#"
|
||||||
msg = ["NOTE: #{target}#{name} is deprecated",
|
msg = ["NOTE: #{target}#{name} is deprecated",
|
||||||
replacement == :none ? ' with no replacement' : "; use #{replacement} instead",
|
replacement == :none ? ' with no replacement' : "; use #{replacement} instead",
|
||||||
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}"
|
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}"
|
||||||
|
|||||||
@ -36,7 +36,7 @@ module ActionController
|
|||||||
type: 'profiles',
|
type: 'profiles',
|
||||||
attributes: {
|
attributes: {
|
||||||
name: 'Name 1',
|
name: 'Name 1',
|
||||||
description: 'Description 1',
|
description: 'Description 1'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,8 @@ module ActionController
|
|||||||
module Serialization
|
module Serialization
|
||||||
class JsonApi
|
class JsonApi
|
||||||
class PaginationTest < ActionController::TestCase
|
class PaginationTest < ActionController::TestCase
|
||||||
KAMINARI_URI = 'http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari'
|
KAMINARI_URI = 'http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_kaminari'.freeze
|
||||||
WILL_PAGINATE_URI = 'http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate'
|
WILL_PAGINATE_URI = 'http://test.host/action_controller/serialization/json_api/pagination_test/pagination_test/render_pagination_using_will_paginate'.freeze
|
||||||
|
|
||||||
class PaginationTestController < ActionController::Base
|
class PaginationTestController < ActionController::Base
|
||||||
def setup
|
def setup
|
||||||
|
|||||||
@ -91,7 +91,7 @@ module ActionController
|
|||||||
|
|
||||||
expires_in = [
|
expires_in = [
|
||||||
PostSerializer._cache_options[:expires_in],
|
PostSerializer._cache_options[:expires_in],
|
||||||
CommentSerializer._cache_options[:expires_in],
|
CommentSerializer._cache_options[:expires_in]
|
||||||
].max + 200
|
].max + 200
|
||||||
|
|
||||||
Timecop.travel(Time.zone.now + expires_in) do
|
Timecop.travel(Time.zone.now + expires_in) do
|
||||||
|
|||||||
@ -43,7 +43,7 @@ module ActiveModelSerializers
|
|||||||
type: 'posts',
|
type: 'posts',
|
||||||
attributes: {
|
attributes: {
|
||||||
title: 'New Post',
|
title: 'New Post',
|
||||||
body: 'Body',
|
body: 'Body'
|
||||||
},
|
},
|
||||||
relationships: {
|
relationships: {
|
||||||
comments: { data: [{ type: 'comments', id: '1' }] },
|
comments: { data: [{ type: 'comments', id: '1' }] },
|
||||||
|
|||||||
@ -98,7 +98,7 @@ module ActiveModelSerializers
|
|||||||
id: '2',
|
id: '2',
|
||||||
type: 'comments',
|
type: 'comments',
|
||||||
attributes: {
|
attributes: {
|
||||||
body: 'ZOMG ANOTHER COMMENT',
|
body: 'ZOMG ANOTHER COMMENT'
|
||||||
},
|
},
|
||||||
relationships: {
|
relationships: {
|
||||||
post: { data: { type: 'posts', id: '10' } },
|
post: { data: { type: 'posts', id: '10' } },
|
||||||
@ -141,7 +141,7 @@ module ActiveModelSerializers
|
|||||||
type: 'bios',
|
type: 'bios',
|
||||||
attributes: {
|
attributes: {
|
||||||
rating: nil,
|
rating: nil,
|
||||||
content: 'Rails Contributor',
|
content: 'Rails Contributor'
|
||||||
},
|
},
|
||||||
relationships: {
|
relationships: {
|
||||||
author: { data: { type: 'authors', id: '2' } }
|
author: { data: { type: 'authors', id: '2' } }
|
||||||
|
|||||||
@ -8,7 +8,7 @@ module ActiveModelSerializers
|
|||||||
module Adapter
|
module Adapter
|
||||||
class JsonApi
|
class JsonApi
|
||||||
class PaginationLinksTest < ActiveSupport::TestCase
|
class PaginationLinksTest < ActiveSupport::TestCase
|
||||||
URI = 'http://example.com'
|
URI = 'http://example.com'.freeze
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
ActionController::Base.cache_store.clear
|
ActionController::Base.cache_store.clear
|
||||||
|
|||||||
@ -77,22 +77,22 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_relationship_block_link
|
def test_relationship_block_link
|
||||||
links = { self: proc { "#{object.id}" } }
|
links = { self: proc { object.id.to_s } }
|
||||||
expected = { links: { self: "#{@blog.id}" } }
|
expected = { links: { self: @blog.id.to_s } }
|
||||||
test_relationship(expected, links: links)
|
test_relationship(expected, links: links)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_relationship_block_link_with_meta
|
def test_relationship_block_link_with_meta
|
||||||
links = {
|
links = {
|
||||||
self: proc do
|
self: proc do
|
||||||
href "#{object.id}"
|
href object.id.to_s
|
||||||
meta(id: object.id)
|
meta(id: object.id)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
expected = {
|
expected = {
|
||||||
links: {
|
links: {
|
||||||
self: {
|
self: {
|
||||||
href: "#{@blog.id}",
|
href: @blog.id.to_s,
|
||||||
meta: { id: @blog.id }
|
meta: { id: @blog.id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ module ActiveModelSerializers
|
|||||||
links = {
|
links = {
|
||||||
self: 'a link',
|
self: 'a link',
|
||||||
related: proc do
|
related: proc do
|
||||||
href "#{object.id}"
|
href object.id.to_s
|
||||||
meta object.id
|
meta object.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
module Rails5Shims
|
module Rails5Shims
|
||||||
module ControllerTests
|
module ControllerTests
|
||||||
# https://github.com/rails/rails/blob/b217354/actionpack/lib/action_controller/test_case.rb
|
# https://github.com/rails/rails/blob/b217354/actionpack/lib/action_controller/test_case.rb
|
||||||
REQUEST_KWARGS = [:params, :session, :flash, :method, :body, :xhr]
|
REQUEST_KWARGS = [:params, :session, :flash, :method, :body, :xhr].freeze
|
||||||
|
|
||||||
# Fold kwargs from test request into args
|
# Fold kwargs from test request into args
|
||||||
# Band-aid for DEPRECATION WARNING
|
# Band-aid for DEPRECATION WARNING
|
||||||
|
|||||||
@ -21,7 +21,7 @@ module SerializationTesting
|
|||||||
ensure
|
ensure
|
||||||
ActiveModelSerializers.config.adapter = old_adapter
|
ActiveModelSerializers.config.adapter = old_adapter
|
||||||
end
|
end
|
||||||
alias_method :with_configured_adapter, :with_adapter
|
alias with_configured_adapter with_adapter
|
||||||
|
|
||||||
def with_config(hash)
|
def with_config(hash)
|
||||||
old_config = config.dup
|
old_config = config.dup
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user