Module: ActiveRecordFlagSupport::FlagInstanceMethods

Defined in:
lib/activerecord_flag_support.rb

Instance Method Summary collapse

Instance Method Details

#set_flag(field, value, bit_field) ⇒ Object

————————————————————— set_flag



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/activerecord_flag_support.rb', line 77

def set_flag(field, value, bit_field)
  is_true = value &&
            ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
  value = if is_true
            (send(field).to_i | bit_field)
          else
            (send(field).to_i & ~bit_field)
          end
  send("#{field}=", value)
  attributes_before_type_cast[field] = value
end