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)
-
+ (Boolean|NilClass) parse(value, raise_errors: false)
Parses a boolean value.
Instance Method Summary (collapse)
-
- (Boolean) check_valid?(value)
Checks if the value is valid for this validator.
-
- (Apes::Validators::BooleanValidator) initialize(options)
constructor
Creates a new validator.
Methods inherited from BaseValidator
Constructor Details
- (Apes::Validators::BooleanValidator) initialize(options)
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
+ (Boolean|NilClass) parse(value, raise_errors: false)
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
- (Boolean) check_valid?(value)
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 |