Sha256: f8800d00e49e1456d0653b4f7e181130746558d57b51b6d7ff569885d2af0cf7

Contents?: true

Size: 569 Bytes

Versions: 21

Compression:

Stored size: 569 Bytes

Contents

# frozen_string_literal: true

module PaidUp
  module Validators
    # Table Rows validator
    class TableRows < ActiveModel::Validator
      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

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
paid_up-0.13.22 lib/paid_up/validators/table_rows.rb
paid_up-0.13.21 lib/paid_up/validators/table_rows.rb
paid_up-0.13.17 lib/paid_up/validators/table_rows.rb
paid_up-0.13.16 lib/paid_up/validators/table_rows.rb
paid_up-0.13.14 lib/paid_up/validators/table_rows.rb
paid_up-0.13.13 lib/paid_up/validators/table_rows.rb
paid_up-0.13.12 lib/paid_up/validators/table_rows.rb
paid_up-0.13.11 lib/paid_up/validators/table_rows.rb
paid_up-0.13.10 lib/paid_up/validators/table_rows.rb
paid_up-0.13.9 lib/paid_up/validators/table_rows.rb
paid_up-0.13.8 lib/paid_up/validators/table_rows.rb
paid_up-0.13.7 lib/paid_up/validators/table_rows.rb
paid_up-0.13.6 lib/paid_up/validators/table_rows.rb
paid_up-0.13.5 lib/paid_up/validators/table_rows.rb
paid_up-0.13.4 lib/paid_up/validators/table_rows.rb
paid_up-0.13.3 lib/paid_up/validators/table_rows.rb
paid_up-0.13.2 lib/paid_up/validators/table_rows.rb
paid_up-0.13.1 lib/paid_up/validators/table_rows.rb
paid_up-0.13.0 lib/paid_up/validators/table_rows.rb
paid_up-0.12.4 lib/paid_up/validators/table_rows.rb