class Toolchain::Validations::Validators::Base
Attributes
data[R]
@return [Hash] 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.
errors[R]
@return [Toolchain::Validations::ValidationErrors] the errors object
of the object that's being validated.
key_path[R]
@return [Symbol] The key_path
of the attribute that's being validated.
message[R]
@return [String] A custom message to override the
default message with in case the attribute is invalid.
object[R]
@return [Object] the object that contains the attribute
that'll be validated.
Public Class Methods
new(object, key_path, data)
click to toggle source
Instantiates a new Toolchain::Validations::Validators
object which'll be used to validate the target object.
@param object [Object] @param key_path
[Object] @param data [Object]
# 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 @message = data[:message] if data.is_a?(Hash) end
Public Instance Methods
value()
click to toggle source
@return [Object] The value that's stored in the attribute of
the object that's being validated.
# 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