Class: Dry::Validation::Message

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

Direct Known Subclasses

Hint, Each

Defined Under Namespace

Classes: Each

Constant Summary collapse

Index =
Class.new {
  def inspect
    "index"
  end
  alias_method :to_s, :inspect
}.new

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.



32
33
34
35
36
37
38
39
40
# File 'lib/dry/validation/message.rb', line 32

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



15
16
17
# File 'lib/dry/validation/message.rb', line 15

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/dry/validation/message.rb', line 15

def options
  @options
end

#pathObject (readonly) Also known as: index_path

Returns the value of attribute path.



15
16
17
# File 'lib/dry/validation/message.rb', line 15

def path
  @path
end

#predicateObject (readonly)

Returns the value of attribute predicate.



15
16
17
# File 'lib/dry/validation/message.rb', line 15

def predicate
  @predicate
end

#ruleObject (readonly)

Returns the value of attribute rule.



15
16
17
# File 'lib/dry/validation/message.rb', line 15

def rule
  @rule
end

#textObject (readonly)

Returns the value of attribute text.



15
16
17
# File 'lib/dry/validation/message.rb', line 15

def text
  @text
end

Class Method Details

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



27
28
29
30
# File 'lib/dry/validation/message.rb', line 27

def self.[](predicate, path, text, options)
  klass = options[:each] ? Message::Each : Message
  klass.new(predicate, path, text, options)
end

Instance Method Details

#each?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/dry/validation/message.rb', line 52

def each?
  @each
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/dry/validation/message.rb', line 64

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

#hint?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/dry/validation/message.rb', line 56

def hint?
  false
end

#root?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/dry/validation/message.rb', line 60

def root?
  path.empty?
end

#signatureObject



48
49
50
# File 'lib/dry/validation/message.rb', line 48

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

#to_sObject



44
45
46
# File 'lib/dry/validation/message.rb', line 44

def to_s
  text
end