Sha256: 25505c347e5f4d8be5c61e751d8db8d95747bc088a87816557a2bf44505d1810

Contents?: true

Size: 639 Bytes

Versions: 4

Compression:

Stored size: 639 Bytes

Contents

module MyFeeds
  module Feeder
    extend ActiveSupport::Concern

    included do
      has_many :source_feeds, class_name: Feed.to_s, as: :source, dependent: :destroy
    end

    module ClassMethods
      def define_feed_event event, conditions = {}
        conditions.freeze
        define_method(event) do |options = {}|
          attributes = {source_type: self.class.to_s, source_id: self.id, event: event}.merge!(conditions).merge! options
          Feed.create attributes
        end

        define_method("#{event}_feeds") do
          source_feeds.where({event: event}.merge! conditions)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
my_feeds-1.0.0 lib/my_feeds/feeder.rb
my_feeds-0.1.1 lib/my_feeds/feeder.rb
my_feeds-0.1.0 lib/my_feeds/feeder.rb
my_feeds-0.0.1 lib/my_feeds/feeder.rb