Class: Ukiryu::Validation::BooleanFlagConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/ukiryu/validation/constraints.rb

Overview

Validates that boolean flags are actually boolean

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Constraint

#applies_to?

Constructor Details

#initialize(attribute_name) ⇒ BooleanFlagConstraint

Returns a new instance of BooleanFlagConstraint.

Parameters:

  • attribute_name (String, Symbol)

    the attribute name



167
168
169
# File 'lib/ukiryu/validation/constraints.rb', line 167

def initialize(attribute_name)
  @attribute_name = attribute_name
end

Instance Attribute Details

#attribute_nameObject (readonly)

Returns the value of attribute attribute_name.



164
165
166
# File 'lib/ukiryu/validation/constraints.rb', line 164

def attribute_name
  @attribute_name
end

Instance Method Details

#validate(value, _context = {}) ⇒ Object

Raises:

  • (ValidationError)

    if flag is not boolean



172
173
174
175
176
177
178
179
# File 'lib/ukiryu/validation/constraints.rb', line 172

def validate(value, _context = {})
  return if value.nil?

  return if [true, false].include?(value)

  raise ValidationIssue.new(@attribute_name, :boolean,
                            "Flag #{@attribute_name} must be boolean, got #{value.class}: #{value}")
end