Class: Apes::Validators::BooleanValidator
- Inherits:
-
BaseValidator
- Object
- ActiveModel::EachValidator
- BaseValidator
- Apes::Validators::BooleanValidator
- Defined in:
- lib/apes/validators.rb
Overview
Validates boolean values.
Class Method Summary collapse
-
.parse(value, raise_errors: false) ⇒ Boolean|NilClass
Parses a boolean value.
Instance Method Summary collapse
-
#check_valid?(value) ⇒ Boolean
Checks if the value is valid for this validator.
-
#initialize(options) ⇒ Apes::Validators::BooleanValidator
constructor
Creates a new validator.
Methods inherited from BaseValidator
Constructor Details
#initialize(options) ⇒ Apes::Validators::BooleanValidator
Creates a new validator.
120 121 122 |
# File 'lib/apes/validators.rb', line 120 def initialize() super(.reverse_merge(default_message: "must be a valid truthy/falsey value")) end |
Class Method Details
.parse(value, raise_errors: false) ⇒ Boolean|NilClass
Parses a boolean value.
111 112 113 114 |
# File 'lib/apes/validators.rb', line 111 def self.parse(value, raise_errors: false) raise(ArgumentError, "Invalid boolean value \"#{value}\".") if !value.nil? && !value.boolean? && raise_errors value.to_boolean end |
Instance Method Details
#check_valid?(value) ⇒ Boolean
Checks if the value is valid for this validator.
128 129 130 |
# File 'lib/apes/validators.rb', line 128 def check_valid?(value) value.blank? || value.boolean? end |