class ActionSet::AttributeValue::BooleanAdapter

Public Class Methods

new(raw, target) click to toggle source
# File lib/action_set/attribute_value.rb, line 126
def initialize(raw, target)
  @raw = raw
  @target = target
end

Public Instance Methods

process() click to toggle source
# File lib/action_set/attribute_value.rb, line 131
def process
  return if @raw.is_a? @target
  return unless @target.eql?(TrueClass) || @target.eql?(FalseClass)

  # ActiveModel::Type::Boolean is too expansive in its casting; will get false positives
  to_bool
end

Private Instance Methods

to_bool() click to toggle source
# File lib/action_set/attribute_value.rb, line 141
def to_bool
  return @raw if @raw.is_a?(TrueClass) || @raw.is_a?(FalseClass)
  return true if %w[true yes 1 t].include? @raw.to_s.downcase
  return false if %w[false no 0 f].include? @raw.to_s.downcase

  nil
end