Module: BitMagic::Adapters::ActiveRecordAdapter

Extended by:
ActiveSupport::Concern
Defined in:
lib/bit_magic/adapters/active_record_adapter.rb

Overview

This is the adapter for ActiveRecord. It’s implemented as a concern to be included inside ActiveRecord::Base subclasses.

It’s expected that you have an integer column (default name ‘flags’, override using the attribute_name option). It’s suggested, though not required, that you set the column as UNSIGNED and NOT NULL.

If you have more than one model that you want to use BitMagic in, it’s recommended that you just include this adapter globally:

require 'bit_magic/adapters/active_record_adapter'
ActiveRecord::Base.include BitMagic::Adapters::ActiveRecordAdapter

Otherwise, you can include it on a per model basis before calling bit_magic

class Example < ActiveRecord::Base
  include BitMagic::Adapters::ActiveRecordAdapter
  bit_magic :settings, 0 => :is_odd, [1, 2, 3] => :amount, 4 => :is_cool
end

After that, you can start using query helpers and instance helpers. Query helpers return a standard ActiveRecord::QueryMethods::WhereChain, so you can do everything you normally can on the query (like chaining conditions). Instance helpers are wrapped around by a Bits object, in this case, ‘settings’ but also have helper methods added based on the name of the fields.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.1.0".freeze