Class: Cuprum::Rails::Serializers::Json::AttributesSerializer
- Inherits:
-
PropertiesSerializer
- Object
- BaseSerializer
- PropertiesSerializer
- Cuprum::Rails::Serializers::Json::AttributesSerializer
- Defined in:
- lib/cuprum/rails/serializers/json/attributes_serializer.rb
Overview
Generates a JSON representation of the object’s attributes.
Defined properties are inherited from the parent serializer. This allows you to extend existing serializers with additional functionality.
Class Method Summary collapse
-
.attribute(name, serializer: nil) {|value| ... } ⇒ Object
Registers the attribute to be serialized.
-
.attributes(*attribute_names, **attribute_mappings) ⇒ Object
Registers the attributes to be serialized.
Methods inherited from PropertiesSerializer
Methods inherited from BaseSerializer
Class Method Details
.attribute(name, serializer: nil) {|value| ... } ⇒ Object
Registers the attribute to be serialized.
89 90 91 92 93 94 95 96 |
# File 'lib/cuprum/rails/serializers/json/attributes_serializer.rb', line 89 def attribute(name, serializer: nil, &block) property( name, scope: name, serializer: serializer, &block ) end |
.attributes(*attribute_names, **attribute_mappings) ⇒ Object
Registers the attributes to be serialized.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/cuprum/rails/serializers/json/attributes_serializer.rb', line 107 def attributes(*attribute_names, **attribute_mappings) require_concrete_class! validate_property_names!(*attribute_names, *attribute_mappings.keys) validate_property_mappings!(*attribute_mappings.values) attribute_names.each { |name| attribute(name) } attribute_mappings.each { |name, mapping| attribute(name, &mapping) } end |