Sha256: eb416c93fa134df09b2cd5548d8b08c3df8c9cf5c49cb62b8dfd2687b7876773

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module ActiveRecord::Rollout::ActsAsFlaggable
  # Sets up ActiveRecord associations for the including class, and includes
  # {ActiveRecord::Rollout::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
      @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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_record_rollout-0.0.1 lib/active_record/rollout/acts_as_flaggable.rb