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.
7 8 9 10 |
# File 'app/serializers/alchemy/base_serializer.rb', line 7 def initialize(object, opts = {}) @object = object @opts = opts end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'app/serializers/alchemy/base_serializer.rb', line 5 def object @object end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
5 6 7 |
# File 'app/serializers/alchemy/base_serializer.rb', line 5 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.
14 15 16 |
# File 'app/serializers/alchemy/base_serializer.rb', line 14 def attributes Hash[object.class.column_names.map { |c| [c, nil] }] end |