class Validate::AST::Rules::Pending

Public Class Methods

new(name, args, block, caller) click to toggle source
# File lib/validate/ast.rb, line 194
def initialize(name, args, block, caller)
  @name = name
  @args = args
  @block = block
  @caller = caller
  @constraint = nil

  extend SingleForwardable
  mon_initialize
end

Public Instance Methods

==(other) click to toggle source
# File lib/validate/ast.rb, line 221
def ==(other)
  load_constraint { return false } == other
end
inspect() click to toggle source
# File lib/validate/ast.rb, line 217
def inspect
  load_constraint { return "[pending #{@name}]" }.inspect
end
method_missing(method, *args) click to toggle source
# File lib/validate/ast.rb, line 225
def method_missing(method, *args)
  load_constraint { return NameError }.__send__(method, *args)
end
name() click to toggle source
# File lib/validate/ast.rb, line 205
def name
  load_constraint { return @name }.name
end
respond_to_missing?(method, pvt = false) click to toggle source
# File lib/validate/ast.rb, line 229
def respond_to_missing?(method, pvt = false)
  load_constraint { return false }.__send__(:respond_to_missing?, method, pvt)
end
to_s() click to toggle source
# File lib/validate/ast.rb, line 213
def to_s
  load_constraint { return "[pending #{@name}]" }.to_s
end
valid?(value, ctx = Constraints::ValidationContext.none) click to toggle source
# File lib/validate/ast.rb, line 209
def valid?(value, ctx = Constraints::ValidationContext.none)
  load_constraint { throw(:pending, true) }.valid?(value, ctx)
end

Private Instance Methods

load_constraint() { || ... } click to toggle source
# File lib/validate/ast.rb, line 235
def load_constraint
  yield unless defined?(Constraints) && Constraints.respond_to?(@name)

  synchronize do
    return @constraint if @constraint

    begin
      @constraint = Constraints.send(@name, *@args, &@block)
    rescue => e
      ::Kernel.raise Error::ValidationRuleError, e.message, @caller
    end

    def_delegators(:@constraint, :name, :valid?, :to_s,
                   :inspect, :==, :message)

    @name = @args = @block = @caller = nil
    @constraint
  end
end