From 08534a8164699017aa847fef62602abf6ec59e8f Mon Sep 17 00:00:00 2001 From: Szymon Szukalski Date: Thu, 24 Oct 2024 12:27:13 +1100 Subject: Add ActionFileExecutor and execute from CLI - Updated tests to use tempfile - Implemented initial ActionFileExecutor tests --- lib/action_file_executor.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/action_file_executor.rb (limited to 'lib/action_file_executor.rb') diff --git a/lib/action_file_executor.rb b/lib/action_file_executor.rb new file mode 100644 index 0000000..15d4f63 --- /dev/null +++ b/lib/action_file_executor.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class ActionFileExecutor + def initialize(file_path) + @file_path = file_path + validate_file + end + + def execute_actions + File.open(@file_path, 'r') do |file| + file.each_line do |line| + action, *params = line.split(' ') + puts "Executing action: #{action} with params: #{params.join(', ')}" + end + end + end + + private + + def validate_file + return if File.exist?(@file_path) + + puts "Error: The file '#{@file_path}' does not exist." + exit 1 + end +end -- cgit v1.2.3