Class: Redcar::FilterCommand::History

Inherits:
Object
  • Object
show all
Defined in:
lib/filter_command/history.rb

Overview

Plugin storage manager for FilterCommand

Constant Summary collapse

STORAGE_SIZE =

How many recent commands to save

30

Class Method Summary collapse

Class Method Details

.clearObject

Clears all saved commands



43
44
45
# File 'lib/filter_command/history.rb', line 43

def self.clear
  FilterCommand.storage['recent_commands'] = []
end

.commandString

The most recently run command

Returns:

  • (String)


24
25
26
# File 'lib/filter_command/history.rb', line 24

def self.command
  @command ||= ""
end

.command_listArray

The commands stored in history

Returns:

  • (Array)

    list of commands



36
37
38
39
40
# File 'lib/filter_command/history.rb', line 36

def self.command_list
  items = []
  recent_commands.each {|map| items << map['command'] }
  items
end

.input_typeString

The last or default used input format

Returns:

  • (String)


18
19
20
# File 'lib/filter_command/history.rb', line 18

def self.input_type
  @input_type ||= "Selection"
end

.output_typeString

The last or default used output format

Returns:

  • (String)


12
13
14
# File 'lib/filter_command/history.rb', line 12

def self.output_type
  @output_type ||= "Replace Selection"
end

.recent_commandsHash

The commands and formats stored in history

Returns:

  • (Hash)


30
31
32
# File 'lib/filter_command/history.rb', line 30

def self.recent_commands
  FilterCommand.storage['recent_commands']
end

.update_commands(command, input_type, output_type) ⇒ Object

Prepends a command and formats into recent history

Parameters:

  • command (String)

    the command

  • input_type (String)

    which input format was used

  • output_type (String)

    which output format was used



51
52
53
54
55
56
57
58
# File 'lib/filter_command/history.rb', line 51

def self.update_commands command, input_type, output_type
  @command, @input_type, @output_type = command, input_type, output_type
  commands = FilterCommand.storage['recent_commands']
  commands.reject! {|item| item['command'] == @command}
  commands.unshift({"command" => @command,"input_type" => @input_type, "output_type" => @output_type })
  commands = commands[0..STORAGE_SIZE]
  FilterCommand.storage['recent_commands'] = commands
end