Module: MultiBitField::InstanceMethods

Defined in:
lib/multi_bit_field.rb

Instance Method Summary collapse

Instance Method Details

#increment_bitfields(column_name, *fields) ⇒ Object Also known as: increment_bitfield

Increases one or more bitfields by 1 value

+increment_bitfield :column, :fields

Examples:

user.increment_bitfield :column, :daily, :monthly

Parameters:

  • column (Symbol)

    name of the column these fields are in

  • field(s) (Symbol)

    name of the field(s) to reset



226
227
228
229
230
# File 'lib/multi_bit_field.rb', line 226

def increment_bitfields column_name, *fields
  mask = self.class.increment_mask_for column_name, *fields
  self[column_name] = self[column_name] += mask
  save
end

#reset_bitfields(column_name, *fields) ⇒ Object Also known as: reset_bitfield

Sets one or more bitfields to 0 within a column

+reset_bitfield :column, :fields

Examples:

user.reset_bitfield :column, :daily, :monthly

Parameters:

  • column (Symbol)

    name of the column these fields are in

  • field(s) (Symbol)

    name of the field(s) to reset



210
211
212
213
214
# File 'lib/multi_bit_field.rb', line 210

def reset_bitfields column_name, *fields
  mask = self.class.reset_mask_for column_name, *fields
  self[column_name] = self[column_name] & mask
  save
end