Class: Alchemy::BaseSerializer

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON
Defined in:
app/serializers/alchemy/base_serializer.rb

Direct Known Subclasses

PageTreeSerializer

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#objectObject (readonly)

Returns the value of attribute object.



7
8
9
# File 'app/serializers/alchemy/base_serializer.rb', line 7

def object
  @object
end

#optsObject (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

#attributesObject

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