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.



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

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'app/serializers/alchemy/base_serializer.rb', line 5

def object
  @object
end

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

#attributesObject

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