Class: Alchemy::BaseSerializer
- Inherits:
-
Object
- Object
- Alchemy::BaseSerializer
- Includes:
- ActiveModel::Serializers::JSON
- Defined in:
- app/serializers/alchemy/base_serializer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#attributes ⇒ Object
The attributes to be serialized.
-
#initialize(object, opts = {}) ⇒ BaseSerializer
constructor
A new instance of BaseSerializer.
Constructor Details
#initialize(object, opts = {}) ⇒ BaseSerializer
Returns a new instance of BaseSerializer.
9 10 11 12 |
# File 'app/serializers/alchemy/base_serializer.rb', line 9 def initialize(object, opts = {}) @object = object @opts = opts end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
7 8 9 |
# File 'app/serializers/alchemy/base_serializer.rb', line 7 def object @object end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
7 8 9 |
# File 'app/serializers/alchemy/base_serializer.rb', line 7 def opts @opts end |
Instance Method Details
#attributes ⇒ Object
The attributes to be serialized. See ActiveModel::Serialization. By default, serialize all columns from the AR object.
16 17 18 |
# File 'app/serializers/alchemy/base_serializer.rb', line 16 def attributes object.class.column_names.map { |c| [c, nil] }.to_h end |