Class: Dry::Validation::Rust::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, path:, meta: {}, code: nil, source: :rule, predicate: nil, args: []) ⇒ Message

Returns a new instance of Message.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dry/validation/rust/message.rb', line 7

def initialize(text:, path:, meta: {}, code: nil, source: :rule, predicate: nil, args: [])
  super(
    text: text.to_s.freeze,
    path: Array(path).freeze,
    meta: meta.freeze,
    code: code&.to_sym,
    source: source,
    predicate: predicate&.to_sym,
    args: args.freeze
  )
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



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

def args
  @args
end

#codeObject (readonly)

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



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

def code
  @code
end

#metaObject (readonly)

Returns the value of attribute meta

Returns:

  • (Object)

    the current value of meta



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

def meta
  @meta
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



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

def path
  @path
end

#predicateObject (readonly)

Returns the value of attribute predicate

Returns:

  • (Object)

    the current value of predicate



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

def predicate
  @predicate
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



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

def source
  @source
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



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

def text
  @text
end

Instance Method Details

#base?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/dry/validation/rust/message.rb', line 19

def base?
  path.compact.empty?
end

#payloadObject



31
32
33
# File 'lib/dry/validation/rust/message.rb', line 31

def payload
  meta.empty? ? text : { text: text, **meta }
end

#rule?Boolean

Returns:

  • (Boolean)


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

def rule?
  source == :rule
end

#schema?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/dry/validation/rust/message.rb', line 23

def schema?
  source == :schema
end

#to_sObject



35
36
37
# File 'lib/dry/validation/rust/message.rb', line 35

def to_s
  text
end