Module: Alba::Serializer::InstanceMethods
- Included in:
- Alba::Serializer
- Defined in:
- lib/alba/serializer.rb
Overview
Instance methods
Instance Method Summary collapse
- #initialize(resource) ⇒ Object
-
#serialize ⇒ String
Use real encoder to actually serialize to JSON.
Instance Method Details
#initialize(resource) ⇒ Object
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 |
#serialize ⇒ String
Use real encoder to actually serialize to JSON
34 35 36 |
# File 'lib/alba/serializer.rb', line 34 def serialize Alba.encoder.call(@hash) end |