Class: Toolchain::Validations::ValidationErrors
- Inherits:
-
Object
- Object
- Toolchain::Validations::ValidationErrors
- Defined in:
- lib/toolchain/validations/validation_errors.rb
Constant Summary collapse
- Helpers =
Toolchain::Validations::Helpers
Instance Attribute Summary collapse
- #errors ⇒ Hash readonly
Instance Method Summary collapse
-
#==(value) ⇒ Boolean
Proxy method to delegate the comparison of two values to the errors Hash.
-
#[](key) ⇒ Object
Proxy method to allow individual values of the errors Hash to be accessed directly through the Toolchain::Validations::ValidationErrors object.
-
#add(*args) ⇒ Object
Adds a new message to the Toolchain::Validations::ValidationErrors object.
-
#empty? ⇒ Boolean
Proxy method to check if there currently are any errors.
-
#initialize ⇒ ValidationErrors
constructor
Creates a new instance of Toolchain::Validations::ValidationErrors and sets the initial errors state to an empty Hash.
-
#reset ⇒ Object
Resets all errors to an empty Hash.
-
#to_hash ⇒ Hash
The Hash representation of the Toolchain::Validations::ValidationErrors.
Constructor Details
#initialize ⇒ ValidationErrors
Creates a new instance of Toolchain::Validations::ValidationErrors and sets the initial errors state to an empty Hash.
12 13 14 |
# File 'lib/toolchain/validations/validation_errors.rb', line 12 def initialize @errors = {} end |
Instance Attribute Details
#errors ⇒ Hash (readonly)
7 8 9 |
# File 'lib/toolchain/validations/validation_errors.rb', line 7 def errors @errors end |
Instance Method Details
#==(value) ⇒ Boolean
Proxy method to delegate the comparison of two values to the errors Hash.
64 65 66 |
# File 'lib/toolchain/validations/validation_errors.rb', line 64 def ==(value) errors == value end |
#[](key) ⇒ Object
Proxy method to allow individual values of the errors Hash to be accessed directly through the Toolchain::Validations::ValidationErrors object.
53 54 55 |
# File 'lib/toolchain/validations/validation_errors.rb', line 53 def [](key) errors[key] end |
#add(*args) ⇒ Object
Adds a new message to the Toolchain::Validations::ValidationErrors object.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/toolchain/validations/validation_errors.rb', line 24 def add(*args) , key_path = args.pop, args key_path = [key_path].flatten Helpers.inject(key_path, errors) do |memo, key, last| if last memo[key] ||= [] memo[key].push() else memo[key] ||= {} end memo[key] end end |
#empty? ⇒ Boolean
Proxy method to check if there currently are any errors.
72 73 74 |
# File 'lib/toolchain/validations/validation_errors.rb', line 72 def empty? errors.empty? end |
#reset ⇒ Object
Resets all errors to an empty Hash.
42 43 44 |
# File 'lib/toolchain/validations/validation_errors.rb', line 42 def reset @errors = {} end |
#to_hash ⇒ Hash
Returns the Hash representation of the Toolchain::Validations::ValidationErrors.
79 80 81 |
# File 'lib/toolchain/validations/validation_errors.rb', line 79 def to_hash errors end |