Class: Rbdantic::ErrorDetail

Inherits:
Object
  • Object
show all
Defined in:
lib/rbdantic/error_detail.rb

Overview

Pydantic-compatible error detail structure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, loc:, msg:, input: nil) ⇒ ErrorDetail



8
9
10
11
12
13
# File 'lib/rbdantic/error_detail.rb', line 8

def initialize(type:, loc:, msg:, input: nil)
  @type = type
  @loc = loc
  @msg = msg
  @input = input
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



6
7
8
# File 'lib/rbdantic/error_detail.rb', line 6

def input
  @input
end

#locObject (readonly)

Returns the value of attribute loc.



6
7
8
# File 'lib/rbdantic/error_detail.rb', line 6

def loc
  @loc
end

#msgObject (readonly)

Returns the value of attribute msg.



6
7
8
# File 'lib/rbdantic/error_detail.rb', line 6

def msg
  @msg
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/rbdantic/error_detail.rb', line 6

def type
  @type
end

Instance Method Details

#as_jsonObject



19
20
21
# File 'lib/rbdantic/error_detail.rb', line 19

def as_json(*)
  to_h
end

#to_hObject



15
16
17
# File 'lib/rbdantic/error_detail.rb', line 15

def to_h
  { type: @type, loc: @loc, msg: @msg, input: @input }.compact
end

#to_json(*args) ⇒ Object



23
24
25
# File 'lib/rbdantic/error_detail.rb', line 23

def to_json(*args)
  to_h.to_json(*args)
end