Class: Dry::Schema::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/schema/message.rb,
lib/dry/schema/extensions/hints.rb

Overview

Hint-specific Message extensions

See Also:

Direct Known Subclasses

Hint

Defined Under Namespace

Classes: Or

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Message.



68
69
70
71
72
73
74
# File 'lib/dry/schema/message.rb', line 68

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

Instance Attribute Details

#argsObject (readonly)



14
15
16
# File 'lib/dry/schema/message.rb', line 14

def args
  @args
end

#optionsObject (readonly)



14
15
16
# File 'lib/dry/schema/message.rb', line 14

def options
  @options
end

#pathObject (readonly)



14
15
16
# File 'lib/dry/schema/message.rb', line 14

def path
  @path
end

#predicateObject (readonly)



14
15
16
# File 'lib/dry/schema/message.rb', line 14

def predicate
  @predicate
end

#textObject (readonly)



14
15
16
# File 'lib/dry/schema/message.rb', line 14

def text
  @text
end

Class Method Details

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build a new message object



63
64
65
# File 'lib/dry/schema/message.rb', line 63

def self.[](predicate, path, text, options)
  Message.new(predicate, path, text, options)
end

Instance Method Details

#<=>(other) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/dry/schema/message.rb', line 88

def <=>(other)
  l_path = Path[path]
  r_path = Path[other.path]

  unless l_path.include?(r_path)
    raise ArgumentError, 'Cannot compare messages from different root paths'
  end

  l_path <=> r_path
end

#eql?(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


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

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

#hint?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


29
30
31
# File 'lib/dry/schema/extensions/hints.rb', line 29

def hint?
  false
end

#to_sObject

Return a string representation of the message



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

def to_s
  text
end