class AdequateSerialization::Serializer
Public Class Methods
attribute(*names, &block)
click to toggle source
# File lib/adequate_serialization/serializer.rb, line 21 def attribute(*names, &block) options = if names.last.is_a?(Hash) names.pop else {} end additions = names.map! { |name| Attribute.from(name, options.dup, &block) } @attributes = attributes + additions end
attributes()
click to toggle source
# File lib/adequate_serialization/serializer.rb, line 17 def attributes @attributes ||= [] end
serializes()
click to toggle source
# File lib/adequate_serialization/serializer.rb, line 35 def serializes return @serializes if defined?(@serializes) class_name = name.gsub(/Serializer\z/, '') begin @serializes = const_get(class_name) rescue NameError raise ClassNotFoundError.new(name, class_name) end end
Public Instance Methods
serialize(model, opts = Options.null)
click to toggle source
# File lib/adequate_serialization/serializer.rb, line 48 def serialize(model, opts = Options.null) self.class.attributes.each_with_object({}) do |attribute, response| attribute.serialize_to(self, response, model, opts.includes) end end