Module: Alba::Serializer::InstanceMethods

Included in:
Alba::Serializer
Defined in:
lib/alba/serializer.rb

Overview

Instance methods

Instance Method Summary collapse

Instance Method Details

#initialize(resource) ⇒ Object

Parameters:



21
22
23
24
25
26
27
28
29
# File 'lib/alba/serializer.rb', line 21

def initialize(resource)
  @resource = resource
  @hash = resource.serializable_hash
  @hash = {key.to_sym => @hash} if key
  return if .empty?

  # @hash is either Hash or Array
  @hash.is_a?(Hash) ? @hash.merge!(.to_h) : @hash << 
end

#serializeString

Use real encoder to actually serialize to JSON

Returns:

  • (String)

    JSON string



34
35
36
# File 'lib/alba/serializer.rb', line 34

def serialize
  Alba.encoder.call(@hash)
end