Method: StoreModel::Model#as_json
- Defined in:
- lib/store_model/model.rb
#as_json(options = {}) ⇒ Hash
Returns a hash representing the model. Some configuration can be passed through options.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/store_model/model.rb', line 34 def as_json( = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize serialize_unknown_attributes = if .key?(:serialize_unknown_attributes) [:serialize_unknown_attributes] else StoreModel.config.serialize_unknown_attributes end serialize_enums_using_as_json = if .key?(:serialize_enums_using_as_json) [:serialize_enums_using_as_json] else StoreModel.config.serialize_enums_using_as_json end result = @attributes.keys.each_with_object({}) do |key, values| values[key] = serialized_attribute(key) end.with_indifferent_access result.merge!(unknown_attributes) if serialize_unknown_attributes result.as_json().tap do |json| serialize_enums!(json) if serialize_enums_using_as_json end end |