Class: Toolchain::Validations::Validators::Base
- Inherits:
-
Object
- Object
- Toolchain::Validations::Validators::Base
- Defined in:
- lib/toolchain/validations/validators/base.rb
Direct Known Subclasses
Acceptance, Confirmation, Email, Exclusion, Format, Inclusion, Length, Presence
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
The value that was passed in to the validator at definition time.
-
#errors ⇒ Toolchain::Validations::ValidationErrors
readonly
The errors object of the object that’s being validated.
-
#key_path ⇒ Symbol
readonly
The key_path of the attribute that’s being validated.
-
#message ⇒ String
readonly
A custom message to override the default message with in case the attribute is invalid.
-
#object ⇒ Object
readonly
The object that contains the attribute that’ll be validated.
Instance Method Summary collapse
-
#initialize(object, key_path, data) ⇒ Base
constructor
Instantiates a new Toolchain::Validations::Validators object which’ll be used to validate the target object.
-
#value ⇒ Object
The value that’s stored in the attribute of the object that’s being validated.
Constructor Details
#initialize(object, key_path, data) ⇒ Base
Instantiates a new Toolchain::Validations::Validators object which’ll be used to validate the target object.
35 36 37 38 39 40 41 |
# File 'lib/toolchain/validations/validators/base.rb', line 35 def initialize(object, key_path, data) @object = object @errors = object.errors @key_path = key_path @data = data = data[:message] if data.is_a?(Hash) end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns The value that was passed in to the validator at definition time. i.e. a Hash containing the regular expression for Toolchain::Validations::Validators::Formatter along with a message.
21 22 23 |
# File 'lib/toolchain/validations/validators/base.rb', line 21 def data @data end |
#errors ⇒ Toolchain::Validations::ValidationErrors (readonly)
Returns the errors object of the object that’s being validated.
11 12 13 |
# File 'lib/toolchain/validations/validators/base.rb', line 11 def errors @errors end |
#key_path ⇒ Symbol (readonly)
Returns The key_path of the attribute that’s being validated.
15 16 17 |
# File 'lib/toolchain/validations/validators/base.rb', line 15 def key_path @key_path end |
#message ⇒ String (readonly)
Returns A custom message to override the default message with in case the attribute is invalid.
26 27 28 |
# File 'lib/toolchain/validations/validators/base.rb', line 26 def end |
#object ⇒ Object (readonly)
Returns the object that contains the attribute that’ll be validated.
6 7 8 |
# File 'lib/toolchain/validations/validators/base.rb', line 6 def object @object end |
Instance Method Details
#value ⇒ Object
Returns The value that’s stored in the attribute of the object that’s being validated.
46 47 48 49 50 51 52 53 |
# File 'lib/toolchain/validations/validators/base.rb', line 46 def value @value ||= ( keys = key_path.dup keys.inject(object.send(keys.shift)) do |memo, key| memo[key] if memo.kind_of?(Hash) end ) end |