Module: Dao::Validations

Included in:
Api, Conducer, Params
Defined in:
lib/dao/validations.rb,
lib/dao/validations/common.rb,
lib/dao/validations/callback.rb,
lib/dao/validations/instance.rb,
lib/dao/validations/validator.rb

Defined Under Namespace

Modules: Common Classes: Callback, Error, Instance, Validator

Constant Summary collapse

ClassMethods =
proc do
  def validator
    @validator ||= Validator.mixin(self)
  end

  def validator=(validator)
    @validator = validator
  end

  %w(
    validations
    validates
    validates_each
  ).each do |method|
    module_eval <<-__, __FILE__, __LINE__
      def self.#{ method }(*args, &block)
        validator.#{ method }(*args, &block)
      end
    __
  end
end
InstanceMethods =
proc do
  def validator
    @validator ||= Validator.mixin(self)
  end

  def validator=(validator)
    @validator = validator
  end

  %w(
    validations
    validates
    validates_each
    validated?
    validated!
    validate
    validate!
    run_validations
    run_validations!
    valid!
    valid?
    forcing_validity?
    errors
  ).each do |method|
    module_eval <<-__, __FILE__, __LINE__
      def #{ method }(*args, &block)
        validator.#{ method }(*args, &block)
      end
    __
  end
end

Class Method Summary collapse

Class Method Details

.add(method_name, &block) ⇒ Object


557
558
559
560
561
# File 'lib/dao/validations/common.rb', line 557

def Validations.add(method_name, &block)
  ::Dao::Validations::Common.module_eval do
    define_method(method_name, &block)
  end
end

.for(*args, &block) ⇒ Object


13
14
15
# File 'lib/dao/validations/instance.rb', line 13

def Validations.for(*args, &block)
  Instance.new(*args, &block)
end

.included(other) ⇒ Object


75
76
77
78
79
80
81
# File 'lib/dao/validations.rb', line 75

def Validations.included(other)
  other.send(:instance_eval, &ClassMethods)
  other.send(:class_eval, &InstanceMethods)
  other.send(:include, Common)
  other.send(:extend, Common)
  super
end

.new(*args, &block) ⇒ Object


9
10
11
# File 'lib/dao/validations/instance.rb', line 9

def Validations.new(*args, &block)
  Instance.new(*args, &block)
end