Class: Dry::Validation::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/validation/message.rb

Direct Known Subclasses

Hint, Check

Defined Under Namespace

Classes: Check, Or

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(predicate, path, text, options) ⇒ Message

Returns a new instance of Message.



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dry/validation/message.rb', line 54

def initialize(predicate, path, text, options)
  @predicate = predicate
  @path = path
  @text = text
  @options = options
  @rule = options[:rule]
  @args = options[:args] || EMPTY_ARRAY

  if predicate == :key?
    @path << rule
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



8
9
10
# File 'lib/dry/validation/message.rb', line 8

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/dry/validation/message.rb', line 8

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/dry/validation/message.rb', line 8

def path
  @path
end

#predicateObject (readonly)

Returns the value of attribute predicate.



8
9
10
# File 'lib/dry/validation/message.rb', line 8

def predicate
  @predicate
end

#ruleObject (readonly)

Returns the value of attribute rule.



8
9
10
# File 'lib/dry/validation/message.rb', line 8

def rule
  @rule
end

#textObject (readonly)

Returns the value of attribute text.



8
9
10
# File 'lib/dry/validation/message.rb', line 8

def text
  @text
end

Class Method Details

.[](predicate, path, text, options) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/dry/validation/message.rb', line 46

def self.[](predicate, path, text, options)
  if options[:check]
    Message::Check.new(predicate, path, text, options)
  else
    Message.new(predicate, path, text, options)
  end
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/dry/validation/message.rb', line 83

def eql?(other)
  other.is_a?(String) ? text == other : super
end

#hint?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/dry/validation/message.rb', line 75

def hint?
  false
end

#root?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/dry/validation/message.rb', line 79

def root?
  path.empty?
end

#signatureObject



71
72
73
# File 'lib/dry/validation/message.rb', line 71

def signature
  @signature ||= [predicate, args, path].hash
end

#to_sObject



67
68
69
# File 'lib/dry/validation/message.rb', line 67

def to_s
  text
end