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( = {}) = self.class.json_field_names.present? ? .merge(only: self.class.json_field_names) : custom_hash = super() 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 |