module PageRecord::Validations

Public Instance Methods

errors() click to toggle source

Searches the record for any errors and returns them

@return [ActiveModel::Errors] the error object for the current record

@raise [AttributeNotFound] when the attribute is not found in the record

# File lib/page_record/validations.rb, line 12
def errors
  found_errors = @record.all('[data-error-for]')
  error_list = ActiveModel::Errors.new(self)
  found_errors.each do | error |
    attribute = error['data-error-for']
    message = error.text
    error_list.add(attribute, message)
  end
  error_list
end
invalid?() click to toggle source

Returns true of there are errors on the current record

@return bool

@raise [AttributeNotFound] when the attribute is not found in the record

# File lib/page_record/validations.rb, line 41
def invalid?
  !valid?
end
valid?() click to toggle source

Returns true of there are no errors on the current record

@return bool

@raise [AttributeNotFound] when the attribute is not found in the record

# File lib/page_record/validations.rb, line 30
def valid?
  errors.empty?
end