Sha256: 254255b7ef19a63767e811953f143f3d0d585894423b3fa50629ccc15f8c663b

Contents?: true

Size: 791 Bytes

Versions: 44

Compression:

Stored size: 791 Bytes

Contents

module Redcar
  class Document
    class History < Array
      attr_reader :max
      
      def initialize(max)
        @max         = max
        @subscribers = []
      end
      
      # Record an action in the History
      def record(action)
        self << action
        notify_subscribers(action)
        truncate
      end
      
      def subscribe(&block)
        @subscribers << block
        block
      end
      
      def unsubscribe(block)
        @subscribers.delete(block)
      end
      
      private
      
      def notify_subscribers(action)
        @subscribers.each {|subscriber| subscriber.call(action)}
      end
      
      def truncate #:nodoc:
        if length > @max + 100
          self[0..(length - @max)] = nil
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
redcar-0.13 plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.13.5dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.13.4dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.13.3dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.13.2dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.13.1dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-0.12.1 plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.13.0dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-0.12 plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.27dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.26dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.25dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.24dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.23dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.22dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.21dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.20dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.19dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.18dev plugins/edit_view/lib/edit_view/document/history.rb
redcar-dev-0.12.17dev plugins/edit_view/lib/edit_view/document/history.rb