re: RuboCop: Bulk minor style corrections

This commit is contained in:
Alexey Dubovskoy 2016-06-20 20:55:44 +01:00
parent 32a3b53892
commit f15f6850de
15 changed files with 41 additions and 143 deletions

View File

@ -11,21 +11,6 @@ Lint/HandleExceptions:
Exclude: Exclude:
- 'Rakefile' - 'Rakefile'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'test/lint_test.rb'
# Offense count: 4
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: strict, flexible
Rails/TimeZone:
Exclude:
- 'test/action_controller/serialization_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.
@ -58,22 +43,7 @@ Style/BracesAroundHashParameters:
Style/ClassAndModuleChildren: Style/ClassAndModuleChildren:
Enabled: false Enabled: false
# Offense count: 6
# Cop supports --auto-correct.
Style/CommentIndentation:
Exclude:
- 'active_model_serializers.gemspec'
# Offense count: 1
Style/DoubleNegation:
Exclude:
- 'lib/active_model/serializable_resource.rb'
# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/active_model/serializer.rb'
# Offense count: 58 # Offense count: 58
# Cop supports --auto-correct. # Cop supports --auto-correct.
@ -82,51 +52,6 @@ Style/GuardClause:
Style/HashSyntax: Style/HashSyntax:
Enabled: false Enabled: false
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray:
Enabled: false
# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Style/IndentHash:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
Style/Lambda:
Exclude:
- 'lib/active_model/serializer.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
Style/MethodDefParentheses:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented
Style/MultilineOperationIndentation:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
Style/NegatedIf:
Exclude:
- 'lib/action_controller/serialization.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/PerlBackrefs:
Exclude:
- 'test/fixtures/poro.rb'
# Offense count: 3 # Offense count: 3
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
@ -138,30 +63,4 @@ Style/PredicateName:
- '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: 1
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
- 'test/fixtures/poro.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowIfMethodIsEmpty.
Style/SingleLineMethods:
Exclude:
- 'test/serializers/serializer_for_test.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: final_newline, final_blank_line
Style/TrailingBlankLines:
Exclude:
- 'test/adapter/null_test.rb'

View File

@ -19,12 +19,13 @@ module ActionController
end end
def serialization_scope def serialization_scope
send(_serialization_scope) if _serialization_scope && return unless _serialization_scope && respond_to?(_serialization_scope, true)
respond_to?(_serialization_scope, true)
send(_serialization_scope)
end end
def get_serializer(resource, options = {}) def get_serializer(resource, options = {})
if !use_adapter? unless use_adapter?
warn 'ActionController::Serialization#use_adapter? has been removed. '\ warn 'ActionController::Serialization#use_adapter? has been removed. '\
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new" "Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
options[:adapter] = false options[:adapter] = false

View File

@ -125,10 +125,9 @@ module ActiveModel
self.root = instance_options[:root] self.root = instance_options[:root]
self.scope = instance_options[:scope] self.scope = instance_options[:scope]
scope_name = instance_options[:scope_name] return if !(scope_name = instance_options[:scope_name]) || respond_to?(scope_name)
if scope_name && !respond_to?(scope_name)
define_singleton_method scope_name, lambda { scope } define_singleton_method scope_name, -> { scope }
end
end end
def success? def success?

View File

@ -36,7 +36,7 @@ module ActiveModelSerializers
target = 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(':')}"]
warn "#{msg.join}." warn "#{msg.join}."
send old, *args, &block send old, *args, &block
end end

View File

@ -21,7 +21,7 @@ module ActiveModelSerializers
# Defaults to the downcased model name and updated_at # Defaults to the downcased model name and updated_at
def cache_key def cache_key
attributes.fetch(:cache_key) { "#{self.class.name.downcase}/#{id}-#{updated_at.strftime("%Y%m%d%H%M%S%9N")}" } attributes.fetch(:cache_key) { "#{self.class.name.downcase}/#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}" }
end end
# Defaults to the time the serializer file was modified. # Defaults to the time the serializer file was modified.

View File

@ -74,7 +74,7 @@ module ActionController
end end
def update_and_render_object_with_cache_enabled def update_and_render_object_with_cache_enabled
@post.updated_at = Time.now @post.updated_at = Time.zone.now
generate_cached_serializer(@post) generate_cached_serializer(@post)
render json: @post render json: @post

View File

@ -22,10 +22,8 @@ module ActiveModelSerializers
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer) adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
assert_equal({ assert_equal({
reviews: { data: [ reviews: { data: [{ type: 'comments', id: '1' },
{ type: 'comments', id: '1' }, { type: 'comments', id: '2' }] },
{ type: 'comments', id: '2' }
] },
writer: { data: { type: 'authors', id: '1' } }, writer: { data: { type: 'authors', id: '1' } },
site: { data: { type: 'blogs', id: '1' } } site: { data: { type: 'blogs', id: '1' } }
}, adapter.serializable_hash[:data][:relationships]) }, adapter.serializable_hash[:data][:relationships])

View File

@ -47,7 +47,7 @@ module ActiveModel
assert_equal(expected_type, hash.fetch(:data).fetch(:type)) assert_equal(expected_type, hash.fetch(:data).fetch(:type))
end end
def with_jsonapi_resource_type inflection def with_jsonapi_resource_type(inflection)
old_inflection = ActiveModelSerializers.config.jsonapi_resource_type old_inflection = ActiveModelSerializers.config.jsonapi_resource_type
ActiveModelSerializers.config.jsonapi_resource_type = inflection ActiveModelSerializers.config.jsonapi_resource_type = inflection
yield yield

View File

@ -20,4 +20,3 @@ module ActiveModelSerializers
end end
end end
end end

View File

@ -101,7 +101,7 @@ module ActiveModelSerializers
uncached_author_serializer = AuthorSerializer.new(uncached_author) uncached_author_serializer = AuthorSerializer.new(uncached_author)
render_object_with_cache(uncached_author) render_object_with_cache(uncached_author)
key = "#{uncached_author_serializer.class._cache_key}/#{uncached_author_serializer.object.id}-#{uncached_author_serializer.object.updated_at.strftime("%Y%m%d%H%M%S%9N")}" key = "#{uncached_author_serializer.class._cache_key}/#{uncached_author_serializer.object.id}-#{uncached_author_serializer.object.updated_at.strftime('%Y%m%d%H%M%S%9N')}"
key = "#{key}/#{adapter.cache_key}" key = "#{key}/#{adapter.cache_key}"
assert_equal(uncached_author_serializer.attributes.to_json, cache_store.fetch(key).to_json) assert_equal(uncached_author_serializer.attributes.to_json, cache_store.fetch(key).to_json)
end end

View File

@ -8,7 +8,7 @@ class Model < ActiveModelSerializers::Model
# Convenience when not adding @attributes readers and writers # Convenience when not adding @attributes readers and writers
def method_missing(meth, *args) def method_missing(meth, *args)
if meth.to_s =~ /^(.*)=$/ if meth.to_s =~ /^(.*)=$/
attributes[$1.to_sym] = args[0] attributes[Regexp.last_match(1).to_sym] = args[0]
elsif attributes.key?(meth) elsif attributes.key?(meth)
attributes[meth] attributes[meth]
else else
@ -64,7 +64,7 @@ VirtualValue = Class.new(Model)
Comment = Class.new(Model) do Comment = Class.new(Model) do
# Uses a custom non-time-based cache key # Uses a custom non-time-based cache key
def cache_key def cache_key
"#{self.class.name.downcase}/#{self.id}" "#{self.class.name.downcase}/#{id}"
end end
end end

View File

@ -30,7 +30,7 @@ module ActiveModel
def errors def errors
end end
def self.human_attribute_name(attr, options = {}) def self.human_attribute_name(_, _ = {})
end end
def self.lookup_ancestors def self.lookup_ancestors

View File

@ -41,7 +41,9 @@ module ActiveModel
end end
class CustomProfile class CustomProfile
def serializer_class; ProfileSerializer; end def serializer_class
ProfileSerializer
end
end end
Tweet = Class.new(::Model) Tweet = Class.new(::Model)