Sha256: 4b3fa1c43eadd59b190f273ff509bba3d48da047755072c4c2ca59b65b5c0754

Contents?: true

Size: 1.1 KB

Versions: 24

Compression:

Stored size: 1.1 KB

Contents

module Redcar
  class Command
    # A class that holds a Redcar command history. The maximum length
    # defaults to 500.
    class History < Array
      def initialize
        @max       = 500
      end
    
      # Clear the command history
      def clear
        super
      end
      
      # Add a command to the command history if CommandHistory.recording is
      # true.
      def record(command)
        if command.class.record?
          self << command
        end
        prune
      end
    
      # Adds a command to the command history if CommandHistory.recording is
      # true. If the last command is of the same class, it is replaced.
      def record_and_replace(command)
        if command.class.record?
          if last.class == command.class
            self[-1] = command
          else
            self << command
          end
        end
        prune
      end
    
      # Set the maximum length of the history
      def max=(max)
        @max = max
      end
      
      private
      
      def prune #:nodoc:
        (length - @max).times { delete_at(0) }
      end
    end
  end
end




Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
redcar-0.6.1 plugins/application/lib/application/command/history.rb
redcar-0.6 plugins/application/lib/application/command/history.rb
redcar-0.6.1dev plugins/application/lib/application/command/history.rb
redcar-0.5.1 plugins/application/lib/application/command/history.rb
redcar-0.5 plugins/application/lib/application/command/history.rb
redcar-0.5.6dev plugins/application/lib/application/command/history.rb
redcar-0.5.5dev plugins/application/lib/application/command/history.rb
redcar-0.5.4dev plugins/application/lib/application/command/history.rb
redcar-0.5.3dev plugins/application/lib/application/command/history.rb
redcar-0.5.2dev plugins/application/lib/application/command/history.rb
redcar-0.5.1dev plugins/application/lib/application/command/history.rb
redcar-0.4.1 plugins/application/lib/application/command/history.rb
redcar-0.4 plugins/application/lib/application/command/history.rb
redcar-0.3.10.1dev plugins/application/lib/application/command/history.rb
redcar-0.3.10.0dev plugins/application/lib/application/command/history.rb
redcar-0.3.9 plugins/application/lib/application/command/history.rb
redcar-0.3.9.0dev plugins/application/lib/application/command/history.rb
redcar-0.3.8.4 plugins/application/lib/application/command/history.rb
redcar-0.3.8.3 plugins/application/lib/application/command/history.rb
redcar-0.3.8.2 plugins/application/lib/application/command/history.rb