class Cuprum::Rails::Serializers::Json::ActiveRecordSerializer

Converts ActiveRecord record to JSON using the as_json method.

Public Instance Methods

call(record, **_) click to toggle source

Converts the ActiveRecord record to JSON.

Calls and returns the as_json method of the record.

@param record [ActiveRecord::Base] The record to convert to JSON.

@return [Hash] a JSON-compatible representation of the record.

# File lib/cuprum/rails/serializers/json/active_record_serializer.rb, line 16
def call(record, **_)
  unless record.is_a?(ActiveRecord::Base)
    raise ArgumentError, 'object must be an ActiveRecord record'
  end

  record.as_json
end