Module: JsonSerializable::InstanceMethods

Defined in:
lib/json_serializable.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/json_serializable.rb', line 16

def as_json(options = {})
  custom_options = self.class.json_field_names.present? ? options.merge(only: self.class.json_field_names) : options
  custom_hash = super(custom_options)

  self.class.json_mappings.each_pair do |key, value|
    custom_hash[key] = value.is_a?(Symbol) ? self.send(value) : value[self]
  end

  custom_hash
end