mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Enforce Rails-style (line-count-based) block style
This commit is contained in:
@@ -58,12 +58,12 @@ module ActiveModel
|
||||
return adapter if adapter.is_a?(Class)
|
||||
adapter_name = adapter.to_s.underscore
|
||||
# 2. return if registered
|
||||
adapter_map.fetch(adapter_name) {
|
||||
adapter_map.fetch(adapter_name) do
|
||||
# 3. try to find adapter class from environment
|
||||
adapter_class = find_by_name(adapter_name)
|
||||
register(adapter_name, adapter_class)
|
||||
adapter_class
|
||||
}
|
||||
end
|
||||
rescue NameError, ArgumentError => e
|
||||
failure_message =
|
||||
"NameError: #{e.message}. Unknown adapter: #{adapter.inspect}. Valid adapters are: #{adapters}"
|
||||
|
||||
@@ -130,14 +130,11 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
def included_resources(include_tree)
|
||||
included = []
|
||||
|
||||
serializer.associations(include_tree).each do |association|
|
||||
add_included_resources_for(association.serializer, include_tree[association.key], included)
|
||||
end
|
||||
|
||||
included
|
||||
def included_for(serializer)
|
||||
included.flat_map do |inc|
|
||||
association = serializer.associations.find { |assoc| assoc.key == inc.first }
|
||||
_included_for(association.serializer, inc.second) if association
|
||||
end.uniq
|
||||
end
|
||||
|
||||
def add_included_resources_for(serializer, include_tree, included)
|
||||
|
||||
@@ -11,9 +11,9 @@ module ActiveModel
|
||||
@root = options[:root]
|
||||
@object = resources
|
||||
@serializers = resources.map do |resource|
|
||||
serializer_class = options.fetch(:serializer) {
|
||||
serializer_class = options.fetch(:serializer) do
|
||||
ActiveModel::Serializer.serializer_for(resource)
|
||||
}
|
||||
end
|
||||
|
||||
if serializer_class.nil?
|
||||
fail NoSerializerError, "No serializer found for resource: #{resource.inspect}"
|
||||
|
||||
Reference in New Issue
Block a user