Class: Attrio::Types::Boolean

Inherits:
Base show all
Defined in:
lib/attrio/types/boolean.rb

Class Method Summary collapse

Methods inherited from Base

default_writer_aliases

Class Method Details

.default_reader_aliases(method_name) ⇒ Object



21
22
23
# File 'lib/attrio/types/boolean.rb', line 21

def self.default_reader_aliases(method_name)
  super.push("#{method_name}?").flatten.uniq
end

.typecast(value, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/attrio/types/boolean.rb', line 6

def self.typecast(value, options = {})
  true_values = options[:true] || options[:true_values] || ['yes', '1', 1, 'true']
  false_values = options[:false] || options[:false_values]

  if false_values.present?
    return Helpers.to_a(false_values).flatten.include?(value) ? false : true
  else
    return Helpers.to_a(true_values).flatten.include?(value) ? true : false
  end
end

.typecasted?(value, options = {}) ⇒ Boolean

Returns:



17
18
19
# File 'lib/attrio/types/boolean.rb', line 17

def self.typecasted?(value, options = {})
  value.is_a?(TrueClass) || value.is_a?(FalseClass)
end