Class: CLI::Replayer
- Inherits:
-
Object
- Object
- CLI::Replayer
- Defined in:
- lib/clir/Replayer.cls.rb
Class Attribute Summary collapse
-
.ison ⇒ Object
readonly
Returns the value of attribute ison.
Class Method Summary collapse
-
.add_input(input) ⇒ Object
Add a Any input value (a Hash, a string, an object, etc.).
- .commands_folder_path ⇒ Object
- .data ⇒ Object
- .get_input ⇒ Object
-
.init_for_recording ⇒ Object
When the command is not replayed (ie not ‘_’), CLI initialize the recordings of inputs.
-
.inputs ⇒ Object
Use ‘get_input’ to get the input in order with ‘pop’.
- .last_command_file(command_name = nil) ⇒ Object
- .load ⇒ Object
-
.on? ⇒ Boolean
(note : it’s running when CLI.main_command is ‘_’).
-
.replayable? ⇒ Boolean
Note: it’s a replayable command if it exists a ‘.<app>_lastcommand’ file in current folder.
-
.save ⇒ Object
Save inputs at the end of the script.
-
.start ⇒ Object
Start running replayer (with ‘_’ main command).
Class Attribute Details
.ison ⇒ Object (readonly)
Returns the value of attribute ison.
5 6 7 |
# File 'lib/clir/Replayer.cls.rb', line 5 def ison @ison end |
Class Method Details
.add_input(input) ⇒ Object
Add a Any input value (a Hash, a string, an object, etc.)
35 36 37 |
# File 'lib/clir/Replayer.cls.rb', line 35 def add_input(input) @inputs << input end |
.commands_folder_path ⇒ Object
84 85 86 |
# File 'lib/clir/Replayer.cls.rb', line 84 def commands_folder_path @commands_folder_path ||= mkdir(File.join(ENV["HOME"] || ENV["USERPROFILE"],'.chir_last_commands')) end |
.data ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/clir/Replayer.cls.rb', line 59 def data @data ||= begin load.tap do |table| CLI.set_command_line_data(table[:data]) end end end |
.get_input ⇒ Object
29 30 31 |
# File 'lib/clir/Replayer.cls.rb', line 29 def get_input @inputs.pop end |
.init_for_recording ⇒ Object
When the command is not replayed (ie not ‘_’), CLI initialize the recordings of inputs
11 12 13 |
# File 'lib/clir/Replayer.cls.rb', line 11 def init_for_recording @inputs = [] end |
.inputs ⇒ Object
Use ‘get_input’ to get the input in order with ‘pop’
42 43 44 45 46 47 |
# File 'lib/clir/Replayer.cls.rb', line 42 def inputs @inputs ||= begin replayable? || raise('Can’t load inputs values: this command is not replayable.') data[:inputs].reverse end end |
.last_command_file(command_name = nil) ⇒ Object
79 80 81 82 |
# File 'lib/clir/Replayer.cls.rb', line 79 def last_command_file(command_name = nil) command_name ||= CLI.command_name File.join(commands_folder_path, command_name) end |
.load ⇒ Object
67 68 69 |
# File 'lib/clir/Replayer.cls.rb', line 67 def load Marshal.load(last_command_file) end |
.on? ⇒ Boolean
(note : it’s running when CLI.main_command is ‘_’)
19 20 21 |
# File 'lib/clir/Replayer.cls.rb', line 19 def on? :TRUE == ison end |
.replayable? ⇒ Boolean
Note: it’s a replayable command if it exists a ‘.<app>_lastcommand’ file in current folder
75 76 77 |
# File 'lib/clir/Replayer.cls.rb', line 75 def replayable? File.exist?(last_command_file(CLI.command_name)) end |
.save ⇒ Object
Save inputs at the end of the script
51 52 53 54 55 56 57 |
# File 'lib/clir/Replayer.cls.rb', line 51 def save table_replay = { inputs: inputs, data: CLI::get_command_line_data } File.write(last_command_file, Marshal.dump(table_replay)) end |
.start ⇒ Object
Start running replayer (with ‘_’ main command)
25 26 27 |
# File 'lib/clir/Replayer.cls.rb', line 25 def start @ison = replayable? ? :TRUE : :FALSE end |