Module: Army::Negative::Column

Defined in:
lib/army-negative/column.rb

Constant Summary collapse

TRUE_VALUES_WITH_NEGATIVE_ONES =

Augments ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES

[-1, '-1']

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object

Called when you extend ActiveRecord::ConnectionAdapters::Column with this module. Uses #alias_method_chain so that #value_to_boolean_with_negative_ones is called instead of #value_to_boolean



14
15
16
17
18
19
20
# File 'lib/army-negative/column.rb', line 14

def self.extended(klass)
  klass.instance_eval do
    class << self
      alias_method_chain :value_to_boolean, :negative_ones
    end
  end
end

Instance Method Details

#value_to_boolean_with_negative_ones(value) ⇒ Object

Replaces #value_to_boolean in order to recognize integer -1 and string ‘-1’ as “true” values.



26
27
28
29
# File 'lib/army-negative/column.rb', line 26

def value_to_boolean_with_negative_ones(value)
  return true if TRUE_VALUES_WITH_NEGATIVE_ONES.include?(value)
  value_to_boolean_without_negative_ones(value)
end