Class: Redcar::FilterCommand::History
- Inherits:
-
Object
- Object
- Redcar::FilterCommand::History
- 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
-
.clear ⇒ Object
Clears all saved commands.
-
.command ⇒ String
The most recently run command.
-
.command_list ⇒ Array
The commands stored in history.
-
.input_type ⇒ String
The last or default used input format.
-
.output_type ⇒ String
The last or default used output format.
-
.recent_commands ⇒ Hash
The commands and formats stored in history.
-
.update_commands(command, input_type, output_type) ⇒ Object
Prepends a command and formats into recent history.
Class Method Details
.clear ⇒ Object
Clears all saved commands
43 44 45 |
# File 'lib/filter_command/history.rb', line 43 def self.clear FilterCommand.storage['recent_commands'] = [] end |
.command ⇒ String
The most recently run command
24 25 26 |
# File 'lib/filter_command/history.rb', line 24 def self.command @command ||= "" end |
.command_list ⇒ Array
The commands stored in history
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_type ⇒ String
The last or default used input format
18 19 20 |
# File 'lib/filter_command/history.rb', line 18 def self.input_type @input_type ||= "Selection" end |
.output_type ⇒ String
The last or default used output format
12 13 14 |
# File 'lib/filter_command/history.rb', line 12 def self.output_type @output_type ||= "Replace Selection" end |
.recent_commands ⇒ Hash
The commands and formats stored in history
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
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 |