Sha256: 542a7f094d8d7866b58eedb97573480b6a55d0b378df2eea3f2e44ff89370f4f

Contents?: true

Size: 955 Bytes

Versions: 1

Compression:

Stored size: 955 Bytes

Contents

module Detour::ActsAsFlaggable
  # Sets up ActiveRecord associations for the including class, and includes
  # {Detour::Flaggable} in the class.
  #
  # @example
  #   class User < ActiveRecord::Base
  #     acts_as_taggable find_by: :email
  #   end
  #
  # @option options [Symbol] :find_by The field to find the record by when
  #   running rake tasks. Defaults to :id.
  def acts_as_flaggable(options = {})
    class_eval do
      @detour_flaggable_find_by = :id

      has_many :flaggable_flags,
        as: :flaggable,
        class_name: "Detour::FlaggableFlag"

      has_many :opt_out_flags,
        as: :flaggable,
        class_name: "Detour::OptOutFlag"

      has_many :features,
        through: :flaggable_flags,
        class_name: "Detour::Feature"

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

      extend  Detour::Flaggable::ClassMethods
      include Detour::Flaggable
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
detour-0.0.1 lib/detour/acts_as_flaggable.rb