Maintaining flag_shih_tzu

Bit Fields for Active Record

Total Downloads Downloads Today Code Quality Network Stars Version Build Documentation Depfu Chat License: MIT

What is a bit field?

What is a bitwise operation?

flag_shih_tzu supports both :bit_operator and :in_list query modes, but only :in_list can will utilize a database index.

What does it look like?

class Lead < ActiveRecord::Base
  include FlagShihTzu
  has_flags 1 => :warm_up_email_sent,
            2 => :follow_up_call_made,
            3 => :final_email_sent,
            4 => :appointment_scheduled,
            5 => :not_interested,
            # You can specify use any integer column to use for flags!
            column: 'actions_taken',
            flag_query_mode: :in_list # or :bit_operator

# Flag values always default to false
lead = true)
# Provides accessors with the same API as a regular boolean column:
lead.warm_up_email_sent # => true
lead.actions_taken # => 1
lead.follow_up_call_made? # => false
lead.follow_up_call_made = true
lead.follow_up_call_made? # => true
lead.actions_taken # => 3
More Reading
comments powered by Disqus