Class: VanillaValidator::RuleParser

Inherits:
Object
  • Object
show all
Defined in:
lib/vanilla_validator/rule_parser.rb

Overview

RuleParser is responsible for parsing validation rules defined in a contract term.

Class Method Summary collapse

Class Method Details

.parse(term) ⇒ Object

Public: Parse a contract term to extract validation rules.

term - The contract term to parse, which may include one or more validation rules separated by '|'.

Returns: An array of Rule objects representing the parsed validation rules.

Examples:

RuleParser.parse('required|min:5') #=> [Rule.new('required', []), Rule.new('min_length', ['5'])]


15
16
17
18
19
20
21
22
23
# File 'lib/vanilla_validator/rule_parser.rb', line 15

def self.parse(term)
  if term.respond_to?(:call)
    [Rule.new('block_rule', term)]
  elsif term.respond_to?(:valid?)
    [Rule.new('custom_rule', term)]
  else
    parse_rules(term)
  end
end