Class: AnyVali::ValidationIssue

Inherits:
Object
  • Object
show all
Defined in:
lib/anyvali/validation_issue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, message: nil, path: [], expected: nil, received: nil, meta: nil) ⇒ ValidationIssue

Returns a new instance of ValidationIssue.



7
8
9
10
11
12
13
14
15
# File 'lib/anyvali/validation_issue.rb', line 7

def initialize(code:, message: nil, path: [], expected: nil, received: nil, meta: nil)
  @code = code
  @message = message || default_message(code)
  @path = path.freeze
  @expected = expected
  @received = received
  @meta = meta
  freeze
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/anyvali/validation_issue.rb', line 5

def code
  @code
end

#expectedObject (readonly)

Returns the value of attribute expected.



5
6
7
# File 'lib/anyvali/validation_issue.rb', line 5

def expected
  @expected
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/anyvali/validation_issue.rb', line 5

def message
  @message
end

#metaObject (readonly)

Returns the value of attribute meta.



5
6
7
# File 'lib/anyvali/validation_issue.rb', line 5

def meta
  @meta
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/anyvali/validation_issue.rb', line 5

def path
  @path
end

#receivedObject (readonly)

Returns the value of attribute received.



5
6
7
# File 'lib/anyvali/validation_issue.rb', line 5

def received
  @received
end

Instance Method Details

#to_hObject



17
18
19
20
21
22
23
24
# File 'lib/anyvali/validation_issue.rb', line 17

def to_h
  h = { "code" => @code, "path" => @path.dup }
  h["expected"] = @expected unless @expected.nil?
  h["received"] = @received unless @received.nil?
  h["message"] = @message if @message
  h["meta"] = @meta if @meta
  h
end