mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Enforce Rails-style (line-count-based) block style
This commit is contained in:
parent
aaa60bfdc1
commit
ca6b193fcb
@ -47,3 +47,7 @@ Style/Documentation:
|
|||||||
|
|
||||||
Style/MultilineOperationIndentation:
|
Style/MultilineOperationIndentation:
|
||||||
EnforcedStyle: indented
|
EnforcedStyle: indented
|
||||||
|
|
||||||
|
Style/BlockDelimiters:
|
||||||
|
Enabled: true
|
||||||
|
EnforcedStyle: line_count_based
|
||||||
|
|||||||
@ -78,12 +78,6 @@ Style/AndOr:
|
|||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/active_model/serializer/lint.rb'
|
- 'lib/active_model/serializer/lint.rb'
|
||||||
|
|
||||||
# Offense count: 6
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
|
||||||
Style/BlockDelimiters:
|
|
||||||
Enabled: false
|
|
||||||
|
|
||||||
# Offense count: 46
|
# Offense count: 46
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
|
|||||||
@ -58,12 +58,12 @@ module ActiveModel
|
|||||||
return adapter if adapter.is_a?(Class)
|
return adapter if adapter.is_a?(Class)
|
||||||
adapter_name = adapter.to_s.underscore
|
adapter_name = adapter.to_s.underscore
|
||||||
# 2. return if registered
|
# 2. return if registered
|
||||||
adapter_map.fetch(adapter_name) {
|
adapter_map.fetch(adapter_name) do
|
||||||
# 3. try to find adapter class from environment
|
# 3. try to find adapter class from environment
|
||||||
adapter_class = find_by_name(adapter_name)
|
adapter_class = find_by_name(adapter_name)
|
||||||
register(adapter_name, adapter_class)
|
register(adapter_name, adapter_class)
|
||||||
adapter_class
|
adapter_class
|
||||||
}
|
end
|
||||||
rescue NameError, ArgumentError => e
|
rescue NameError, ArgumentError => e
|
||||||
failure_message =
|
failure_message =
|
||||||
"NameError: #{e.message}. Unknown adapter: #{adapter.inspect}. Valid adapters are: #{adapters}"
|
"NameError: #{e.message}. Unknown adapter: #{adapter.inspect}. Valid adapters are: #{adapters}"
|
||||||
|
|||||||
@ -130,14 +130,11 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def included_resources(include_tree)
|
def included_for(serializer)
|
||||||
included = []
|
included.flat_map do |inc|
|
||||||
|
association = serializer.associations.find { |assoc| assoc.key == inc.first }
|
||||||
serializer.associations(include_tree).each do |association|
|
_included_for(association.serializer, inc.second) if association
|
||||||
add_included_resources_for(association.serializer, include_tree[association.key], included)
|
end.uniq
|
||||||
end
|
|
||||||
|
|
||||||
included
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_included_resources_for(serializer, include_tree, included)
|
def add_included_resources_for(serializer, include_tree, included)
|
||||||
|
|||||||
@ -11,9 +11,9 @@ module ActiveModel
|
|||||||
@root = options[:root]
|
@root = options[:root]
|
||||||
@object = resources
|
@object = resources
|
||||||
@serializers = resources.map do |resource|
|
@serializers = resources.map do |resource|
|
||||||
serializer_class = options.fetch(:serializer) {
|
serializer_class = options.fetch(:serializer) do
|
||||||
ActiveModel::Serializer.serializer_for(resource)
|
ActiveModel::Serializer.serializer_for(resource)
|
||||||
}
|
end
|
||||||
|
|
||||||
if serializer_class.nil?
|
if serializer_class.nil?
|
||||||
fail NoSerializerError, "No serializer found for resource: #{resource.inspect}"
|
fail NoSerializerError, "No serializer found for resource: #{resource.inspect}"
|
||||||
|
|||||||
@ -400,25 +400,25 @@ module ActionController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_warn_overridding_use_adapter_as_falsy_on_controller_instance
|
def test_warn_overridding_use_adapter_as_falsy_on_controller_instance
|
||||||
controller = Class.new(ImplicitSerializationTestController) {
|
controller = Class.new(ImplicitSerializationTestController) do
|
||||||
def use_adapter?
|
def use_adapter?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
}.new
|
end.new
|
||||||
assert_match(/adapter: false/, (capture(:stderr) {
|
assert_match(/adapter: false/, (capture(:stderr) do
|
||||||
controller.get_serializer(Profile.new)
|
controller.get_serializer(Profile.new)
|
||||||
}))
|
end))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dont_warn_overridding_use_adapter_as_truthy_on_controller_instance
|
def test_dont_warn_overridding_use_adapter_as_truthy_on_controller_instance
|
||||||
controller = Class.new(ImplicitSerializationTestController) {
|
controller = Class.new(ImplicitSerializationTestController) do
|
||||||
def use_adapter?
|
def use_adapter?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
}.new
|
end.new
|
||||||
assert_equal '', (capture(:stderr) {
|
assert_equal '', (capture(:stderr) do
|
||||||
controller.get_serializer(Profile.new)
|
controller.get_serializer(Profile.new)
|
||||||
})
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -28,9 +28,9 @@ class CaptureWarnings
|
|||||||
|
|
||||||
# rubocop:disable Metrics/AbcSize
|
# rubocop:disable Metrics/AbcSize
|
||||||
def after_tests(lines)
|
def after_tests(lines)
|
||||||
app_warnings, other_warnings = lines.partition { |line|
|
app_warnings, other_warnings = lines.partition do |line|
|
||||||
line.include?(app_root) && !line.include?(bundle_dir)
|
line.include?(app_root) && !line.include?(bundle_dir)
|
||||||
}
|
end
|
||||||
|
|
||||||
header = "#{'-' * 22} app warnings: #{'-' * 22}"
|
header = "#{'-' * 22} app warnings: #{'-' * 22}"
|
||||||
output.puts
|
output.puts
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user