Module: Vanguard::DSL

Included in:
Validator::Builder
Defined in:
lib/vanguard/dsl.rb,
lib/vanguard/dsl/evaluator.rb

Overview

Mixin for the Vanguard dsl

Defined Under Namespace

Classes: Evaluator

Constant Summary collapse

REGISTRY =
{}

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hook called when method is missing

Parameters:

  • method_name (Symbol)

Returns:

  • (self)


32
33
34
35
36
37
38
39
40
# File 'lib/vanguard/dsl.rb', line 32

def method_missing(method_name, *arguments)
  klass = REGISTRY.fetch(method_name) { super }

  Evaluator.new(klass, arguments).rules.each do |rule|
    add(rule)
  end

  self
end

Class Method Details

.register(name, klass) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register macro

Parameters:

  • name (Symbol)
  • klass (Class)

Returns:

  • (self)


19
20
21
22
# File 'lib/vanguard/dsl.rb', line 19

def self.register(name, klass)
  REGISTRY[name] = klass
  self
end