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.



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

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.



6
7
8
# File 'lib/dry/validation/message.rb', line 6

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/dry/validation/message.rb', line 6

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/dry/validation/message.rb', line 6

def path
  @path
end

#predicateObject (readonly)

Returns the value of attribute predicate.



6
7
8
# File 'lib/dry/validation/message.rb', line 6

def predicate
  @predicate
end

#ruleObject (readonly)

Returns the value of attribute rule.



6
7
8
# File 'lib/dry/validation/message.rb', line 6

def rule
  @rule
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/dry/validation/message.rb', line 6

def text
  @text
end

Class Method Details

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



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

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)


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

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

#hint?Boolean

Returns:

  • (Boolean)


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

def hint?
  false
end

#root?Boolean

Returns:

  • (Boolean)


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

def root?
  path.empty?
end

#signatureObject



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

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

#to_sObject



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

def to_s
  text
end