Sha256: c4186ea7fe697d179ddb5fca9726588a8b850f43b9c2ab6efd1d1760d5c5871a

Contents?: true

Size: 757 Bytes

Versions: 3

Compression:

Stored size: 757 Bytes

Contents

module Clockwork
  module DatabaseEvents
    class EventCollection

      def initialize(manager=Clockwork.manager)
        @events = []
        @manager = manager
      end

      def add(event)
        @events << event
      end

      def has_changed?(model)
        return true if event.nil?

        event.model_attributes != model.attributes
      end

      def unregister
        events.each{|e| manager.unregister(e) }
      end

      private

      attr_reader :events, :manager

      # All events in the same collection (for a model instance) are equivalent
      # so we can use any of them. Only their @at variable will be different,
      # but we don't care about that here.
      def event
        events.first
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
clockwork-2.0.2 lib/clockwork/database_events/event_collection.rb
clockwork-2.0.1 lib/clockwork/database_events/event_collection.rb
clockwork-2.0.0 lib/clockwork/database_events/event_collection.rb