Document Serializer settings and private api [ci skip]

This commit is contained in:
Benjamin Fleischer 2015-12-10 15:08:22 -06:00
parent 386a567dfc
commit bf8270b8b4
2 changed files with 5 additions and 0 deletions

View File

@ -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)

View File

@ -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) }