lib/hash_delegator.rb in markdown_exec-1.8 vs lib/hash_delegator.rb in markdown_exec-1.8.1
- old
+ new
@@ -382,10 +382,11 @@
def command_execute(command, args: [])
@run_state.files = Hash.new([])
@run_state.options = @delegate_object
@run_state.started_at = Time.now.utc
+# rbp
Open3.popen3(@delegate_object[:shell],
'-c', command,
@delegate_object[:filename],
*args) do |stdin, stdout, stderr, exec_thr|
@@ -788,11 +789,12 @@
unless [MenuState::BACK,
MenuState::CONTINUE].include?(block_state.state)
return
end
- @delegate_object[:block_name] = block_state.block[:dname]
+ @delegate_object[:block_name] = block_state.block[:oname]
+# rbp
@menu_user_clicked_back_link = block_state.state == MenuState::BACK
end
# This method is responsible for handling the execution of generic blocks in a markdown document.
# It collects the required code lines from the document and, depending on the configuration,
@@ -800,10 +802,11 @@
#
# @param mdoc [Object] The markdown document object containing code blocks.
# @param selected [Hash] The selected item from the menu to be executed.
# @return [LoadFileNextBlock] An object indicating whether to load the next block or reuse the current one.
def handle_generic_block(mdoc, selected)
+# rbp
required_lines = collect_required_code_lines(mdoc, selected)
output_or_approval = @delegate_object[:output_script] || @delegate_object[:user_must_approve]
display_required_code(required_lines) if output_or_approval
allow_execution = @delegate_object[:user_must_approve] ? prompt_for_user_approval(required_lines) : true
execute_approved_block(required_lines, selected) if allow_execution
@@ -1106,10 +1109,11 @@
end
def next_block_name_from_command_line_arguments
return MenuControl::Repeat unless @delegate_object[:input_cli_rest].present?
+# rbp
@delegate_object[:block_name] = @delegate_object[:input_cli_rest].pop
MenuControl::Fresh
end
def output_execution_result
@@ -1298,10 +1302,11 @@
loop do
loop do
@delegate_object = @menu_base_options.dup
@menu_base_options[:filename] = @menu_state_filename
+# rbp
@menu_base_options[:block_name] = @menu_state_block_name
@menu_state_filename = nil
@menu_state_block_name = nil
@menu_user_clicked_back_link = false
@@ -1330,13 +1335,15 @@
if @delegate_object[:dump_selected_block]
warn block_state.block.to_yaml.sub(/^(?:---\n)?/, "Block:\n")
end
+# rbp
load_file_next_block = approve_and_execute_block(block_state.block,
mdoc)
default = load_file_next_block.load_file == LoadFile::Load ? nil : @delegate_object[:block_name]
+# rbp
@menu_base_options[:block_name] =
@delegate_object[:block_name] = load_file_next_block.next_block
@menu_base_options[:filename] = @delegate_object[:filename]
# user prompt to exit if the menu will be displayed again
@@ -1581,17 +1588,17 @@
# Handles the core logic for generating the command file's metadata and content.
def write_command_file(required_lines)
return unless @delegate_object[:save_executed_script]
+# rbp
time_now = Time.now.utc
@run_state.saved_script_filename =
SavedAsset.script_name(blockname: @delegate_object[:block_name],
filename: @delegate_object[:filename],
prefix: @delegate_object[:saved_script_filename_prefix],
time: time_now)
-
@run_state.saved_filespec =
File.join(@delegate_object[:saved_script_folder],
@run_state.saved_script_filename)
shebang = if @delegate_object[:shebang]&.present?
@@ -2273,33 +2280,33 @@
@mock_block_state = mock('block_state')
end
def test_handle_block_state_with_back
@mock_block_state.stubs(:state).returns(MenuState::BACK)
- @mock_block_state.stubs(:block).returns({ dname: 'sample_block' })
+ @mock_block_state.stubs(:block).returns({ oname: 'sample_block' })
@hd.handle_block_state(@mock_block_state)
assert_equal 'sample_block',
@hd.instance_variable_get(:@delegate_object)[:block_name]
assert @hd.instance_variable_get(:@menu_user_clicked_back_link)
end
def test_handle_block_state_with_continue
@mock_block_state.stubs(:state).returns(MenuState::CONTINUE)
- @mock_block_state.stubs(:block).returns({ dname: 'another_block' })
+ @mock_block_state.stubs(:block).returns({ oname: 'another_block' })
@hd.handle_block_state(@mock_block_state)
assert_equal 'another_block',
@hd.instance_variable_get(:@delegate_object)[:block_name]
refute @hd.instance_variable_get(:@menu_user_clicked_back_link)
end
def test_handle_block_state_with_other
@mock_block_state.stubs(:state).returns(nil) # MenuState::OTHER
- @mock_block_state.stubs(:block).returns({ dname: 'other_block' })
+ @mock_block_state.stubs(:block).returns({ oname: 'other_block' })
@hd.handle_block_state(@mock_block_state)
assert_nil @hd.instance_variable_get(:@delegate_object)[:block_name]
assert_nil @hd.instance_variable_get(:@menu_user_clicked_back_link)
@@ -2730,11 +2737,11 @@
@hd.stubs(:error_handler)
end
def test_wait_for_user_selected_block_with_back_state
mock_block_state = Struct.new(:state, :block).new(MenuState::BACK,
- { dname: 'back_block' })
+ { oname: 'back_block' })
@hd.stubs(:wait_for_user_selection).returns(mock_block_state)
result = @hd.wait_for_user_selected_block([], ['Block 1', 'Block 2'],
nil)
@@ -2744,10 +2751,10 @@
assert_equal mock_block_state, result
end
def test_wait_for_user_selected_block_with_continue_state
mock_block_state = Struct.new(:state, :block).new(
- MenuState::CONTINUE, { dname: 'continue_block' }
+ MenuState::CONTINUE, { oname: 'continue_block' }
)
@hd.stubs(:wait_for_user_selection).returns(mock_block_state)
result = @hd.wait_for_user_selected_block([], ['Block 1', 'Block 2'],
nil)