Class: ValidatesBySchema::ValidationOption
- Inherits:
-
Object
- Object
- ValidatesBySchema::ValidationOption
- Defined in:
- lib/validates_by_schema/validation_option.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
column here must be an ActiveRecord column i.e.
-
#klass ⇒ Object
column here must be an ActiveRecord column i.e.
-
#unique_indexes ⇒ Object
column here must be an ActiveRecord column i.e.
Instance Method Summary collapse
- #define! ⇒ Object
-
#initialize(klass, column, unique_indexes = []) ⇒ ValidationOption
constructor
A new instance of ValidationOption.
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
#column ⇒ Object
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 |
#klass ⇒ Object
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_indexes ⇒ Object
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 |