Sha256: a5d04c1fa272bc737c114388f36ee6ba29a1c8956fcf0d61c4919e25b3d9e43e

Contents?: true

Size: 853 Bytes

Versions: 10

Compression:

Stored size: 853 Bytes

Contents

module FlexibleFeeds
  module ActsAsModerator
    extend ActiveSupport::Concern
 
    module ClassMethods
      def acts_as_moderator

        has_many :moderator_joins, as: :moderator,
          class_name: "FlexibleFeeds::ModeratorJoin", dependent: :destroy
        has_many :moderated_feeds, through: :moderator_joins, source: :feed,
          class_name: "FlexibleFeeds::Feed"

        send :include, InstanceMethods
      end
    end

    module InstanceMethods
      def moderate(feed)
        moderator_joins.create(feed: feed)
      end

      def unmoderate(feed)
        join = moderator_joins.find_by(feed: feed)
        return false if join.nil?
        join.destroy
      end

      def is_moderating?(feed)
        moderated_feeds.include?(feed)
      end
    end
  end
end

ActiveRecord::Base.send :include, FlexibleFeeds::ActsAsModerator

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
flexible_feeds-0.4.0 lib/flexible_feeds/acts_as_moderator.rb
flexible_feeds-0.3.6 lib/flexible_feeds/acts_as_moderator.rb
flexible_feeds-0.3.5 lib/flexible_feeds/acts_as_moderator.rb
flexible_feeds-0.3.4 lib/flexible_feeds/acts_as_moderator.rb
flexible_feeds-0.3.3 lib/flexible_feeds/acts_as_moderator.rb
flexible_feeds-0.3.2 lib/flexible_feeds/acts_as_moderator.rb
flexible_feeds-0.3.1 lib/flexible_feeds/acts_as_moderator.rb
flexible_feeds-0.3.0 lib/flexible_feeds/acts_as_moderator.rb
flexible_feeds-0.2.1 lib/flexible_feeds/acts_as_moderator.rb
flexible_feeds-0.1.0 lib/flexible_feeds/acts_as_moderator.rb