Module: PageRecord::Validations

Included in:
Base
Defined in:
lib/page_record/validations.rb

Instance Method Summary collapse

Instance Method Details

#errorsActiveModel::Errors

Searches the record for any errors and returns them

Returns:

  • (ActiveModel::Errors)

    the error object for the current record

Raises:



12
13
14
15
16
17
18
19
20
21
# 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?Boolean

Returns true of there are errors on the current record

Returns:

  • (Boolean)

    bool

Raises:



41
42
43
# File 'lib/page_record/validations.rb', line 41

def invalid?
  !valid?
end

#valid?Boolean

Returns true of there are no errors on the current record

Returns:

  • (Boolean)

    bool

Raises:



30
31
32
# File 'lib/page_record/validations.rb', line 30

def valid?
  errors.empty?
end