Module: ActiveRecord::Rollout::ActsAsFlaggable

Defined in:
lib/active_record/rollout/acts_as_flaggable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_flaggable(options = {}) ⇒ Object

Sets up ActiveRecord associations for the including class, and includes Flaggable in the class.

Examples:

class User < ActiveRecord::Base
  acts_as_taggable find_by: :email
end

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :find_by (Symbol)

    The field to find the record by when running rake tasks. Defaults to :id.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_record/rollout/acts_as_flaggable.rb', line 12

def acts_as_flaggable(options = {})
  class_eval do
    @active_record_rollout_flaggable_find_by = :id

    has_many :flaggable_flags,
      as: :flaggable,
      class_name: "ActiveRecord::Rollout::FlaggableFlag"

    has_many :opt_out_flags,
      as: :flaggable,
      class_name: "ActiveRecord::Rollout::OptOutFlag"

    has_many :features,
      through: :flaggable_flags,
      class_name: "ActiveRecord::Rollout::Feature"

    if options[:find_by]
      @active_record_rollout_flaggable_find_by = options[:find_by]
    end

    extend  ActiveRecord::Rollout::Flaggable::ClassMethods
    include ActiveRecord::Rollout::Flaggable
  end
end