Class: Schematic::Generator::ColumnValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/schematic/generator/column_validator.rb

Direct Known Subclasses

Restrictions::Base, Uniqueness

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, column) ⇒ ColumnValidator

Returns a new instance of ColumnValidator.



6
7
8
9
# File 'lib/schematic/generator/column_validator.rb', line 6

def initialize(klass, column)
  @klass = klass
  @column = column
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



4
5
6
# File 'lib/schematic/generator/column_validator.rb', line 4

def column
  @column
end

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/schematic/generator/column_validator.rb', line 4

def klass
  @klass
end

Instance Method Details

#for_validator(validator_klass) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/schematic/generator/column_validator.rb', line 11

def for_validator(validator_klass)
  validators_for_column.each do |column_validation|
    next unless column_validation.is_a? validator_klass
    has_conditional_proc = !column_validation.options[:if].nil? || !column_validation.options[:unless].nil?
    force_inclusion = column_validation.options[:xsd] && column_validation.options[:xsd][:include]
    next if has_conditional_proc && !force_inclusion
    yield(column_validation)
    return
  end
end

#validators_for_columnObject



22
23
24
25
# File 'lib/schematic/generator/column_validator.rb', line 22

def validators_for_column
  return [] unless klass.respond_to?(:_validators)
  klass._validators[column.name.to_sym]
end