Module: Mv::Core::Db::Helpers::ColumnValidators
Instance Attribute Summary collapse
#table_name
Instance Method Summary
collapse
#delete_table_validators, #table_validators, #update_table_validators
Instance Attribute Details
#column_name ⇒ Object
Returns the value of attribute column_name.
11
12
13
|
# File 'lib/mv/core/db/helpers/column_validators.rb', line 11
def column_name
@column_name
end
|
Instance Method Details
#column_validators ⇒ Object
13
14
15
|
# File 'lib/mv/core/db/helpers/column_validators.rb', line 13
def column_validators
table_validators.where(column_name: column_name)
end
|
#create_column_validator(validation_type, opts) ⇒ Object
17
18
19
20
21
|
# File 'lib/mv/core/db/helpers/column_validators.rb', line 17
def create_column_validator validation_type, opts
raise_column_validation_error(validation_type, opts) if opts == false
update_column_validator(validation_type, opts)
end
|
#delete_column_validator ⇒ Object
23
24
25
|
# File 'lib/mv/core/db/helpers/column_validators.rb', line 23
def delete_column_validator
delete_validators(column_validators) > 0
end
|
#rename_column(new_column_name) ⇒ Object
35
36
37
|
# File 'lib/mv/core/db/helpers/column_validators.rb', line 35
def rename_column new_column_name
column_validators.update_all(column_name: new_column_name)
end
|
#update_column_validator(validation_type, opts) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/mv/core/db/helpers/column_validators.rb', line 27
def update_column_validator validation_type, opts
return delete_validators(column_validators.where(validation_type: validation_type)) if opts == false
column_validators.where(validation_type: validation_type).first_or_initialize.tap do |validator|
validator.options = normalize_opts(validation_type, opts)
end.save!
end
|