Class: AdequateSerialization::Serializer
- Inherits:
-
Object
- Object
- AdequateSerialization::Serializer
- Defined in:
- lib/adequate_serialization/serializer.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.attribute(*names, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/adequate_serialization/serializer.rb', line 10 def attribute(*names, &block) = if names.last.is_a?(Hash) names.pop else {} end additions = names.map! { |name| Attribute.from(name, .dup, &block) } @attributes = attributes + additions end |
.attributes ⇒ Object
6 7 8 |
# File 'lib/adequate_serialization/serializer.rb', line 6 def attributes @attributes ||= [] end |
Instance Method Details
#serialize(model, opts = Options.null) ⇒ Object
25 26 27 28 29 |
# File 'lib/adequate_serialization/serializer.rb', line 25 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 |