Class: Dry::Validation::Message

Inherits:
Object
  • Object
show all
Includes:
Core::Constants
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.



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

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.



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

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#predicateObject (readonly)

Returns the value of attribute predicate.



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

def predicate
  @predicate
end

#ruleObject (readonly)

Returns the value of attribute rule.



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

def rule
  @rule
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

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



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

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)


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

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

#hint?Boolean

Returns:

  • (Boolean)


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

def hint?
  false
end

#root?Boolean

Returns:

  • (Boolean)


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

def root?
  path.empty?
end

#signatureObject



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

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

#to_sObject



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

def to_s
  text
end