Class: PaidUp::Validators::TableRows

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/paid_up/validators/table_rows.rb

Overview

Table Rows validator

Instance Method Summary collapse

Instance Method Details

#found_in_valid?(record, found_in) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/paid_up/validators/table_rows.rb', line 15

def found_in_valid?(record, found_in)
  ActiveRecord::Base.connection.data_source_exists? record.send(found_in)
end

#validate(record) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/paid_up/validators/table_rows.rb', line 7

def validate(record)
  found_in = options[:found_in]
  if record.send(options[:field]) == options[:comparison] &&
     !found_in_valid?(record, found_in)
    record.errors[found_in] << :when_using_table_rows_table_must_exist.l
  end
end