Class: PaidUp::Validators::RolifyRows

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

Overview

RolifyRows Validator

Instance Method Summary collapse

Instance Method Details

#found_in_valid?(record, found_in) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/paid_up/validators/rolify_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/rolify_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_rolify_rows_table_must_exist.l
  end
end