Sha256: 995aa9600fa69a856098b6f5ed305db95b3ccfea2afa9f0b28e97333c218a266

Contents?: true

Size: 1.11 KB

Versions: 44

Compression:

Stored size: 1.11 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
        truncate
      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
        truncate
      end
    
      # Set the maximum length of the history
      def max=(max)
        @max = max
      end
      
      private
      
      def truncate #:nodoc:
        (length - @max).times { delete_at(0) }
      end
    end
  end
end




Version data entries

44 entries across 44 versions & 2 rubygems

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