Class: Poncho::Params::BooleanStringParam

Inherits:
Poncho::Param show all
Defined in:
lib/poncho/params/boolean_string.rb

Instance Attribute Summary

Attributes inherited from Poncho::Param

#name, #options

Instance Method Summary collapse

Methods inherited from Poncho::Param

#initialize, type, #type

Constructor Details

This class inherits a constructor from Poncho::Param

Instance Method Details

#convert(value) ⇒ Object



12
13
14
15
16
# File 'lib/poncho/params/boolean_string.rb', line 12

def convert(value)
  return true if value == 'yes'
  return false if value == 'no'
  nil
end

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/poncho/params/boolean_string.rb', line 4

def validate_each(record, attribute, value)
  converted = convert(value)

  if !(converted.is_a?(TrueClass) || converted.is_a?(FalseClass))
    record.errors.add(attribute, :invalid_boolean_string, options.merge(:value => value))
  end
end