Module: AtomicJson::Validations

Included in:
Query
Defined in:
lib/atomic_json/validations.rb

Instance Method Summary collapse

Instance Method Details

#validate_attributes!(record, attributes) ⇒ Object

Raises:



13
14
15
16
17
18
19
# File 'lib/atomic_json/validations.rb', line 13

def validate_attributes!(record, attributes)
  raise TypeError, 'Payload to update must be a hash' unless attributes.is_a?(Hash)
  attributes.each_key do |key|
    raise ReadOnlyAttributeError, "#{key} is marked as readonly" if read_only_attribute?(record, key)
    raise InvalidColumnTypeError, 'ActiveRecord column needs to be of type JSON or JSONB' unless valid_column_type?(record, key)
  end
end

#validate_record!(record) ⇒ Object

Raises:



8
9
10
11
# File 'lib/atomic_json/validations.rb', line 8

def validate_record!(record)
  raise ActiveRecordError, 'cannot update a new record' if record.new_record?
  raise ActiveRecordError, 'cannot update a destroyed record' if record.destroyed?
end