Class: ValidatesBySchema::ValidationOption

Inherits:
Object
  • Object
show all
Defined in:
lib/validates_by_schema/validation_option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, column, unique_indexes = []) ⇒ ValidationOption

Returns a new instance of ValidationOption.



6
7
8
9
10
# File 'lib/validates_by_schema/validation_option.rb', line 6

def initialize(klass, column, unique_indexes = [])
  @klass = klass
  @column = column
  @unique_indexes = unique_indexes.select { |index| index.columns.first == column.name }
end

Instance Attribute Details

#columnObject

column here must be an ActiveRecord column i.e. MyARModel.columns.first



4
5
6
# File 'lib/validates_by_schema/validation_option.rb', line 4

def column
  @column
end

#klassObject

column here must be an ActiveRecord column i.e. MyARModel.columns.first



4
5
6
# File 'lib/validates_by_schema/validation_option.rb', line 4

def klass
  @klass
end

#unique_indexesObject

column here must be an ActiveRecord column i.e. MyARModel.columns.first



4
5
6
# File 'lib/validates_by_schema/validation_option.rb', line 4

def unique_indexes
  @unique_indexes
end

Instance Method Details

#define!Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/validates_by_schema/validation_option.rb', line 12

def define!
  if association
    # Only presence and uniqueness are handled for associations.
    # presence on the association name, uniqueness on the column name.
    define_belongs_to_presence_validation
  else
    define_validations(to_hash)
  end
  define_uniqueness_validations
end