mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06:50 +00:00
Document Serializer settings and private api [ci skip]
This commit is contained in:
parent
386a567dfc
commit
bf8270b8b4
@ -1,6 +1,7 @@
|
|||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
module Attributes
|
module Attributes
|
||||||
|
# @api private
|
||||||
class Attribute
|
class Attribute
|
||||||
delegate :call, to: :reader
|
delegate :call, to: :reader
|
||||||
|
|
||||||
@ -19,12 +20,14 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# @api private
|
||||||
class AttributeReader < Attribute
|
class AttributeReader < Attribute
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
super(name)
|
super(name)
|
||||||
@reader = ->(instance) { instance.read_attribute_for_serialization(name) }
|
@reader = ->(instance) { instance.read_attribute_for_serialization(name) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# @api private
|
||||||
class AttributeBlock < Attribute
|
class AttributeBlock < Attribute
|
||||||
def initialize(name, block)
|
def initialize(name, block)
|
||||||
super(name)
|
super(name)
|
||||||
|
|||||||
@ -35,10 +35,12 @@ module ActiveModel
|
|||||||
@reader = self.class.build_reader(name, block)
|
@reader = self.class.build_reader(name, block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @api private
|
||||||
def value(instance)
|
def value(instance)
|
||||||
call(instance)
|
call(instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @api private
|
||||||
def self.build_reader(name, block)
|
def self.build_reader(name, block)
|
||||||
if block
|
if block
|
||||||
->(instance) { instance.read_attribute_for_serialization(name).instance_eval(&block) }
|
->(instance) { instance.read_attribute_for_serialization(name).instance_eval(&block) }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user