Module: ActiveForm::Validator

Includes:
Mixins::LoaderMethods
Defined in:
lib/active_form/validator.rb

Defined Under Namespace

Classes: Base, MismatchException, NoElemException

Class Method Summary collapse

Methods included from Mixins::LoaderMethods

included

Class Method Details

.base_load_pathsObject



23
24
25
# File 'lib/active_form/validator.rb', line 23

def base_load_paths
  [::File.join(ActiveForm::BASE_PATH, 'validators')]
end

.create(definition_name, &block) ⇒ Object



32
33
34
# File 'lib/active_form/validator.rb', line 32

def create(definition_name, &block)
  ActiveForm::Validator::Base::create(definition_name, &block)
end

.instance(definition_name, klass, *args, &block) ⇒ Object



27
28
29
30
# File 'lib/active_form/validator.rb', line 27

def instance(definition_name, klass, *args, &block)
  item = klass.new(*args, &block)
  item
end

.load_pathsObject

loader related



19
20
21
# File 'lib/active_form/validator.rb', line 19

def load_paths
  @@load_paths ||= [*base_load_paths]
end

.register(elem_class) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/active_form/validator.rb', line 36

def register(elem_class)
  if validator?(elem_class) && !self.methods.include?("validates_#{elem_class.loadable_type}")       
    self.module_eval("
      def validates_#{elem_class.loadable_type}(*args, &block)
        define_validator(:#{elem_class.loadable_type}, *args, &block)
      end")
  end
end

.validator?(klass) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/active_form/validator.rb', line 13

def validator?(klass)
  klass < ActiveForm::Validator::Base
end