flag_shih_tzu

Bit Fields for Active Record

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

What is a bit field?

https://en.wikipedia.org/wiki/Bit_field

What is a bitwise operation?

https://en.wikipedia.org/wiki/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
end

# Flag values always default to false
lead = Lead.new(warm_up_email_sent: 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
Newer// debug_logging
Older// gem_bench
comments powered by Disqus