Sha256: 6793d1735f004bdec47b4a308c3c211641033d5660135444e679129a2cf8d6fe

Contents?: true

Size: 795 Bytes

Versions: 1

Compression:

Stored size: 795 Bytes

Contents

module FlexibleFeeds
  module ActsAsFeedable
    extend ActiveSupport::Concern
 
    module ClassMethods
      def acts_as_feedable(options = {})

        cattr_accessor :has_many_feeds
        self.has_many_feeds = options[:has_many] || false

        if has_many_feeds == true
          has_many :feeds, as: :feedable, class_name: "FlexibleFeeds::Feed",
            dependent: :destroy
        else
          has_one :feed, as: :feedable, class_name: "FlexibleFeeds::Feed",
            dependent: :destroy
          after_create :create_feed
        end

        send :include, InstanceMethods
      end
    end

    module InstanceMethods
      def feed_named(name)
        feeds.find_by(name: name)
      end
    end
  end
end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flexible_feeds-0.1.0 lib/flexible_feeds/acts_as_feedable.rb