mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Rubocop: Consistent spacing
This commit is contained in:
@@ -20,7 +20,7 @@ module ActionController
|
||||
end
|
||||
|
||||
def get_serializer(resource, options = {})
|
||||
if ! use_adapter?
|
||||
if !use_adapter?
|
||||
warn 'ActionController::Serialization#use_adapter? has been removed. '\
|
||||
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource#serialize"
|
||||
options[:adapter] = false
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
require 'set'
|
||||
module ActiveModel
|
||||
class SerializableResource
|
||||
|
||||
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter])
|
||||
|
||||
def initialize(resource, options = {})
|
||||
@@ -79,6 +78,5 @@ module ActiveModel
|
||||
ActiveModelSerializers.silence_warnings do
|
||||
attr_reader :resource, :adapter_opts, :serializer_opts
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,6 @@ module ActiveModel
|
||||
include Configuration
|
||||
include Associations
|
||||
|
||||
|
||||
# Matches
|
||||
# "c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'"
|
||||
# AND
|
||||
|
||||
@@ -2,7 +2,6 @@ module ActiveModel
|
||||
class Serializer
|
||||
class Adapter
|
||||
class FragmentCache
|
||||
|
||||
attr_reader :serializer
|
||||
|
||||
def initialize(adapter, serializer, options)
|
||||
@@ -35,7 +34,7 @@ module ActiveModel
|
||||
|
||||
def cached_attributes(klass, serializers)
|
||||
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
|
||||
|
||||
cached_attributes.each do |attribute|
|
||||
@@ -60,7 +59,7 @@ module ActiveModel
|
||||
Object.const_set cached, Class.new(ActiveModel::Serializer) unless Object.const_defined?(cached)
|
||||
Object.const_set non_cached, Class.new(ActiveModel::Serializer) unless Object.const_defined?(non_cached)
|
||||
|
||||
klass._cache_options ||= {}
|
||||
klass._cache_options ||= {}
|
||||
klass._cache_options[:key] = klass._cache_key if klass._cache_key
|
||||
|
||||
cached.constantize.cache(klass._cache_options)
|
||||
@@ -68,7 +67,7 @@ module ActiveModel
|
||||
cached.constantize.fragmented(serializer)
|
||||
non_cached.constantize.fragmented(serializer)
|
||||
|
||||
serializers = {cached: cached, non_cached: non_cached}
|
||||
serializers = { cached: cached, non_cached: non_cached }
|
||||
cached_attributes(klass, serializers)
|
||||
serializers
|
||||
end
|
||||
|
||||
@@ -46,7 +46,6 @@ module ActiveModel
|
||||
def fragment_cache(cached_hash, non_cached_hash)
|
||||
Json::FragmentCache.new().fragment_cache(cached_hash, non_cached_hash)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,11 +4,9 @@ module ActiveModel
|
||||
class Adapter
|
||||
class Json < Adapter
|
||||
class FragmentCache
|
||||
|
||||
def fragment_cache(cached_hash, non_cached_hash)
|
||||
non_cached_hash.merge cached_hash
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,7 +50,7 @@ module ActiveModel
|
||||
resource[:relationships][name][:data] += serializers.map { |serializer| { type: serializer.json_api_type, id: serializer.id.to_s } }
|
||||
end
|
||||
|
||||
def add_relationship(resource, name, serializer, val=nil)
|
||||
def add_relationship(resource, name, serializer, val = nil)
|
||||
resource[:relationships] ||= {}
|
||||
resource[:relationships][name] = { data: val }
|
||||
|
||||
|
||||
@@ -4,19 +4,17 @@ module ActiveModel
|
||||
class Adapter
|
||||
class JsonApi < Adapter
|
||||
class FragmentCache
|
||||
|
||||
def fragment_cache(root, cached_hash, non_cached_hash)
|
||||
hash = {}
|
||||
core_cached = cached_hash.first
|
||||
core_non_cached = non_cached_hash.first
|
||||
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_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] }
|
||||
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.deep_merge no_root_non_cache.deep_merge no_root_cache
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,6 @@ module ActiveModel
|
||||
# Association.new(:comments, CommentSummarySerializer)
|
||||
#
|
||||
Association = Struct.new(:name, :serializer, :options) do
|
||||
|
||||
# @return [Symbol]
|
||||
#
|
||||
def key
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class Fieldset
|
||||
|
||||
def initialize(fields, root = nil)
|
||||
@root = root
|
||||
@raw_fields = fields
|
||||
@@ -16,7 +15,7 @@ module ActiveModel
|
||||
fields[key.to_sym] || fields[key.pluralize.to_sym]
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
ActiveModelSerializers.silence_warnings do
|
||||
attr_reader :raw_fields, :root
|
||||
@@ -24,7 +23,7 @@ module ActiveModel
|
||||
|
||||
def parsed_fields
|
||||
if raw_fields.is_a?(Hash)
|
||||
raw_fields.inject({}) { |h,(k,v)| h[k.to_sym] = v.map(&:to_sym); h}
|
||||
raw_fields.inject({}) { |h, (k, v)| h[k.to_sym] = v.map(&:to_sym); h }
|
||||
elsif raw_fields.is_a?(Array)
|
||||
if root.nil?
|
||||
raise ArgumentError, 'The root argument must be specified if the fileds argument is an array.'
|
||||
@@ -36,7 +35,6 @@ module ActiveModel
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,6 @@ module ActiveModel::Serializer::Lint
|
||||
# always return +{}+, and the tests would pass. It is up to you to ensure
|
||||
# that the values are semantically meaningful.
|
||||
module Tests
|
||||
|
||||
# Passes if the object responds to <tt>serializable_hash</tt> and if it takes
|
||||
# zero or one arguments.
|
||||
# Fails otherwise.
|
||||
@@ -126,6 +125,5 @@ module ActiveModel::Serializer::Lint
|
||||
def assert_instance_of(result, name)
|
||||
assert result.instance_of?(name), "#{result} should be an instance of #{name}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,6 @@ module ActiveModelSerializers
|
||||
ensure
|
||||
$VERBOSE = verbose
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
require 'active_model'
|
||||
|
||||
Reference in New Issue
Block a user