Sha256: 22cc22cc06ea2432eae8ed25db8336cab1e0820bb80172dcf73fed8ba304c866

Contents?: true

Size: 1014 Bytes

Versions: 5

Compression:

Stored size: 1014 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?

        ignored_attributes = model.ignored_attributes if model.respond_to?(:ignored_attributes)
        ignored_attributes ||= []

        model_attributes = model.attributes.select do |k, _|
          not ignored_attributes.include?(k.to_sym)
        end

        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

5 entries across 5 versions & 1 rubygems

Version Path
clockwork-3.0.2 lib/clockwork/database_events/event_collection.rb
clockwork-3.0.1 lib/clockwork/database_events/event_collection.rb
clockwork-3.0.0 lib/clockwork/database_events/event_collection.rb
clockwork-2.0.4 lib/clockwork/database_events/event_collection.rb
clockwork-2.0.3 lib/clockwork/database_events/event_collection.rb