class Mv::Core::Validation::Factory

Public Instance Methods

create_validation(table_name, column_name, validation_type, opts) click to toggle source
# File lib/mv/core/validation/factory.rb, line 16
def create_validation table_name, column_name, validation_type, opts
  validation_class = factory_map[validation_type.to_sym]

  raise Mv::Core::Error.new(table_name: table_name,
                            column_name: column_name,
                            validation_type: validation_type,
                            opts: opts,
                            error: "Validation '#{validation_type}' is not supported") unless validation_class

  validation_class.new(table_name, column_name, opts)
end
register_validation(validation_type, klass) click to toggle source
# File lib/mv/core/validation/factory.rb, line 28
def register_validation validation_type, klass
  factory_map[validation_type.to_sym] = klass
end
register_validations(opts) click to toggle source
# File lib/mv/core/validation/factory.rb, line 32
def register_validations opts
  opts.each do |validation_type, klass|
    register_validation(validation_type, klass)
  end
end
registered_validations() click to toggle source
# File lib/mv/core/validation/factory.rb, line 38
def registered_validations
  factory_map.keys
end

Private Instance Methods

factory_map() click to toggle source
# File lib/mv/core/validation/factory.rb, line 51
def factory_map
  @factory_map ||= {
    uniqueness: Mv::Core::Validation::Uniqueness,
    exclusion: Mv::Core::Validation::Exclusion,
    inclusion: Mv::Core::Validation::Inclusion,
    length: Mv::Core::Validation::Length,
    presence: Mv::Core::Validation::Presence,
    absence: Mv::Core::Validation::Absence,
    custom: Mv::Core::Validation::Custom
  }
end