Class: NxtSchema::Validator::ValidateWithProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/nxt_schema/validators/validate_with_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ ValidateWithProxy

Returns a new instance of ValidateWithProxy.



4
5
6
7
# File 'lib/nxt_schema/validators/validate_with_proxy.rb', line 4

def initialize(node)
  @node = node
  @aggregated_errors = []
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



9
10
11
# File 'lib/nxt_schema/validators/validate_with_proxy.rb', line 9

def node
  @node
end

Instance Method Details

#add_error(error) ⇒ Object



20
21
22
23
# File 'lib/nxt_schema/validators/validate_with_proxy.rb', line 20

def add_error(error)
  aggregated_errors << error
  false
end

#copy_aggregated_errors_to_nodeObject



25
26
27
28
29
# File 'lib/nxt_schema/validators/validate_with_proxy.rb', line 25

def copy_aggregated_errors_to_node
  aggregated_errors.each do |error|
    node.add_error(error)
  end
end

#validate(&block) ⇒ Object



13
14
15
16
17
18
# File 'lib/nxt_schema/validators/validate_with_proxy.rb', line 13

def validate(&block)
  result = instance_exec(&block)
  return if result

  copy_aggregated_errors_to_node
end