Class: Ippon::Validate::Errors
- Inherits:
-
Object
- Object
- Ippon::Validate::Errors
- Defined in:
- lib/ippon/validate.rb
Overview
Stores information about errors.
Instance Attribute Summary collapse
-
#children ⇒ Hash
readonly
private
Child results.
-
#steps ⇒ Arary<Step>
readonly
Steps that produced an error.
Instance Method Summary collapse
-
#[](key) ⇒ Errors | nil
A nested error.
-
#add_child(key, result) ⇒ Object
private
Adds another
Errors
object as a child error. -
#add_step(step) ⇒ Object
private
Adds a step as an error.
-
#deep_freeze ⇒ Object
private
Deeply freezes the object.
-
#each_step_with_path {|step, path| ... } ⇒ self | Enumerator
Yields all steps (including nested steps) that caused an error.
-
#empty? ⇒ Boolean
true
if there are no errors. -
#initialize ⇒ Errors
constructor
private
A new instance of Errors.
-
#merge!(other) ⇒ Object
private
Merges another
Errors
object into this one.
Constructor Details
#initialize ⇒ Errors
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 Errors.
381 382 383 384 |
# File 'lib/ippon/validate.rb', line 381 def initialize @steps = [] @children = {} end |
Instance Attribute Details
#children ⇒ Hash (readonly)
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 child results.
378 379 380 |
# File 'lib/ippon/validate.rb', line 378 def children @children end |
#steps ⇒ Arary<Step> (readonly)
Returns steps that produced an error.
374 375 376 |
# File 'lib/ippon/validate.rb', line 374 def steps @steps end |
Instance Method Details
#[](key) ⇒ Errors | nil
Returns a nested error.
402 403 404 405 406 |
# File 'lib/ippon/validate.rb', line 402 def [](key) if result = @children[key] result.errors end end |
#add_child(key, result) ⇒ 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.
Adds another Errors
object as a child error.
439 440 441 442 443 444 445 |
# File 'lib/ippon/validate.rb', line 439 def add_child(key, result) if @children.has_key?(key) raise ArgumentError, "a result with key #{key.inspect} already exists" end @children[key] = result self end |
#add_step(step) ⇒ 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.
Adds a step as an error.
430 431 432 433 |
# File 'lib/ippon/validate.rb', line 430 def add_step(step) @steps << step self end |
#deep_freeze ⇒ 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.
Deeply freezes the object.
388 389 390 391 392 393 |
# File 'lib/ippon/validate.rb', line 388 def deep_freeze @steps.freeze @children.freeze freeze self end |
#each_step_with_path {|step, path| ... } ⇒ self | Enumerator
Yields all steps (including nested steps) that caused an error.
413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/ippon/validate.rb', line 413 def each_step_with_path return enum_for(:each_step_with_path) if !block_given? @steps.each do |step| yield step, [] end @children.each do |key, result| result.errors.each_step_with_path do |step, path| yield step, [key, *path] end end end |
#empty? ⇒ Boolean
Returns true
if there are no errors.
396 397 398 |
# File 'lib/ippon/validate.rb', line 396 def empty? @steps.empty? && @children.empty? end |
#merge!(other) ⇒ 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.
Merges another Errors
object into this one.
450 451 452 453 454 455 456 |
# File 'lib/ippon/validate.rb', line 450 def merge!(other) @steps.concat(other.steps) @children.merge!(other.children) do |key| raise ArgumentError, "duplicate errors for key #{key.inspect}" end self end |