Top Level Namespace

Includes:
CLI, Tap

Defined Under Namespace

Modules: ArrayUtil, CLI, ClassMethodWrapper, CompactionHelpers, Env, Exceptions, HashDelegatorSelf, ImwUx, InstanceMethodWrapper, MarkdownExec, PathUtils, StringUtil, Tap Classes: AnsiFormatter, Array, BashCommentFormatter, BashCommentFormatterTest, BlockLabel, BlockLabelTest, BlockType, CachedNestedFileReader, CachedNestedFileReaderTest, DirectorySearcher, DirectorySearcherTest, DirectorySearcherTest2, ExecutionStreams, FCBTest, FOut, FalseClass, FileMissingError, Hash, IndexedLine, InputSequencer, LinkKeys, LoadFile, LoadFileLinkState, MDE, MenuControl, MenuOptions, MenuState, NestedLine, Object, OptionValueTest, Regexp, RegexpGsubFormatTest, SavedAssetTest, SavedFilesMatcherTest, SelectedBlockMenuState, StdOutErrLogger, StdOutErrLoggerTest, String, TestFindFiles, TestObjectMethods, TestStringMethods

Constant Summary collapse

BF =
'bin'
DISPLAY_LEVEL_BASE =

display_level values

0
DISPLAY_LEVEL_ADMIN =

required output

1
DISPLAY_LEVEL_DEBUG =

monit

2
DISPLAY_LEVEL_DUMP =
3
DISPLAY_LEVEL_DEFAULT =
DISPLAY_LEVEL_ADMIN
DISPLAY_LEVEL_MAX =
DISPLAY_LEVEL_DUMP
LOCAL_YML =
'menu.yml'
"lib/#{LOCAL_YML}"
SHELL_COLOR_OPTIONS =
{
  BlockType::BASH => :menu_bash_color,
  BlockType::LINK => :menu_link_color,
  BlockType::OPTS => :menu_opts_color,
  BlockType::VARS => :menu_vars_color
}.freeze
ARGV_SEP =
'--'

Constants included from Tap

Tap::ALL, Tap::ALL2, Tap::CVT, Tap::DN, Tap::NONE, Tap::T1, Tap::T2, Tap::T3, Tap::T4, Tap::TB1, Tap::TB2, Tap::TB3, Tap::TD, Tap::TD0, Tap::TD1, Tap::TD2, Tap::TDD, Tap::TP, Tap::TP0, Tap::TP1, Tap::TP2

Instance Method Summary collapse

Methods included from Tap

#tap_config, #tap_inspect, #tap_print, #tap_pry, #tap_puts, #tap_yaml

Methods included from Env

#env_bool, #env_bool_false, #env_int, #env_str

Methods included from CLI

#value_for_cli

Instance Method Details

#bpp(*args) ⇒ Object



68
69
70
71
72
# File 'lib/markdown_exec.rb', line 68

def bpp(*args)
  pp '+ bpp()'
  pp(*args.map.with_index { |line, ind| "  - #{ind}: #{line}" })
  rbi
end

#dp(str) ⇒ Object



53
54
55
# File 'lib/markdown_exec.rb', line 53

def dp(str)
  lout " => #{str}", level: DISPLAY_LEVEL_DEBUG
end

#extract_named_captures_from_option(str, option) ⇒ Object

convert regex match groups to a hash with symbol keys

:reek:UtilityFunction



84
85
86
# File 'lib/markdown_exec.rb', line 84

def extract_named_captures_from_option(str, option)
  str.match(Regexp.new(option))&.named_captures&.sym_keys
end

#find_files(pattern, paths = ['', Dir.pwd], exclude_dirs: false) ⇒ Object

Finds files matching a given pattern within specified directory paths while optionally excluding “.” and “..” entries and directory names from the results.

The function takes a pattern (filename or pattern with wildcards), an array of paths, and an option to exclude directory entries and special entries “.” and “..”. It searches for files matching the pattern within each of the specified paths. Hidden files are included in the search. The search can include subdirectories depending on the path specification (e.g., ‘dir/**’ for recursive search).

Args:

pattern (String): A filename or a pattern string with wildcards.
paths (Array<String>): An array of directory paths where the search will be performed.
  Paths can include wildcards for recursive search.
exclude_dirs (Boolean): If true, excludes "." and ".." and directory names from the results.

Returns:

Array<String>: A unique list of file paths that match the given pattern in the specified paths,
excluding directories if exclude_dirs is true.

Example:

find_files('version.rb', ['lib/**', 'spec'], true)
# This might return file paths like ['lib/markdown_exec/version.rb', 'spec/version_spec.rb'].


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/find_files.rb', line 29

def find_files(pattern, paths = ['', Dir.pwd], exclude_dirs: false)
  matched_files = []

  paths.each do |path_with_wildcard|
    # Combine the path with the wildcard and the pattern
    search_pattern = File.join(path_with_wildcard, pattern)

    # Use Dir.glob with the File::FNM_DOTMATCH flag to include hidden files
    files = Dir.glob(search_pattern, File::FNM_DOTMATCH)

    # Optionally exclude "." and ".." and directory names
    files.reject! { |file| file.end_with?('/.', '/..') || File.directory?(file) } if exclude_dirs

    matched_files += files
  end

  matched_files.uniq
end

#format_and_highlight_dependencies(dependencies, highlight_color_sym: :exception_color_detail, plain_color_sym: :menu_chrome_color, label: 'Dependencies:', highlight: [], line_prefix: ' ', line_postfix: '', detail_sep: ' ') ⇒ String

Formats and highlights a list of dependencies. Dependencies are presented with indentation, and specific items can be highlighted in a specified color, while others are shown in a plain color.

Parameters:

  • dependencies (Hash)

    A hash of dependencies, where each key is a dependency name, and its value is an array of sub-items.

  • highlight_color_sym (Symbol) (defaults to: :exception_color_detail)

    The color method to apply to highlighted items. Default is :exception_color_detail.

  • plain_color_sym (Symbol) (defaults to: :menu_chrome_color)

    The color method for non-highlighted items. Default is :menu_chrome_color.

  • label (String) (defaults to: 'Dependencies:')

    The label to prefix the list of dependencies with. Default is ‘Dependencies:’.

  • highlight (Array) (defaults to: [])

    An array of items to highlight. Each item in this array will be formatted with the specified highlight color.

  • line_prefix (String) (defaults to: ' ')

    Prefix for each line. Default is ‘ ’.

  • line_postfix (String) (defaults to: '')

    Postfix for each line. Default is ”.

  • detail_sep (String) (defaults to: ' ')

    Separator for items in the sub-list. Default is ‘ ’.

Returns:

  • (String)

    A formatted string representation of the dependencies with highlighted items.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/directory_searcher.rb', line 50

def format_and_highlight_dependencies(
  dependencies,
  highlight_color_sym: :exception_color_detail,
  plain_color_sym: :menu_chrome_color,
  label: 'Dependencies:',
  highlight: [],
  line_prefix: '  ',
  line_postfix: '',
  detail_sep: '  '
)
  formatted_deps = dependencies&.map do |dep_name, sub_items|
    formatted_sub_items = sub_items.map do |item|
      color_sym = highlight.include?(item) ? highlight_color_sym : plain_color_sym
      string_send_color(item, color_sym)
    end.join(detail_sep)

    "#{line_prefix}- #{string_send_color(dep_name,
                                         highlight.include?(dep_name) ? highlight_color_sym : plain_color_sym)}: #{formatted_sub_items}#{line_postfix}"
  end || []

  "#{line_prefix}#{string_send_color(label,
                                     highlight_color_sym)}#{line_postfix}\n" + formatted_deps.join("\n")
end

#format_and_highlight_hash(data, highlight_color_sym: :exception_color_detail, plain_color_sym: :menu_chrome_color, label: 'Data:', highlight: [], line_prefix: ' ', line_postfix: '', key_has_value: ': ') ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/directory_searcher.rb', line 9

def format_and_highlight_hash(
  data,
  highlight_color_sym: :exception_color_detail,
  plain_color_sym: :menu_chrome_color,
  label: 'Data:',
  highlight: [],
  line_prefix: '  ',
  line_postfix: '',
  key_has_value: ': '
)
  formatted_deps = data&.map do |key, value|
    color_sym = highlight.include?(key) ? highlight_color_sym : plain_color_sym
    dkey = string_send_color(key, color_sym)

    "#{line_prefix}#{dkey}#{key_has_value}" \
     "#{string_send_color(value,
                          highlight.include?(value) ? highlight_color_sym : plain_color_sym)}: " \
     "#{formatted_sub_items}#{line_postfix}"
  end

  "#{line_prefix}#{string_send_color(label,
                                     highlight_color_sym)}#{line_postfix}\n" + formatted_deps.join("\n")
end

#format_and_highlight_lines(lines, highlight_color_sym: :exception_color_detail, plain_color_sym: :menu_chrome_color, label: 'Dependencies:', highlight: [], line_prefix: ' ', line_postfix: '') ⇒ Object

warn menu_blocks.to_yaml.sub(/^(?:—n)?/, “MenuBlocks:n”)



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/directory_searcher.rb', line 75

def format_and_highlight_lines(
  lines,
  highlight_color_sym: :exception_color_detail,
  plain_color_sym: :menu_chrome_color,
  label: 'Dependencies:',
  highlight: [],
  line_prefix: '  ',
  line_postfix: ''
)
  formatted_deps = lines&.map do |item|
    "#{line_prefix}- #{string_send_color(dep_name,
                                         highlight.include?(dep_name) ? highlight_color_sym : plain_color_sym)}: #{item}#{line_postfix}"
  end || []

  "#{line_prefix}#{string_send_color(label,
                                     highlight_color_sym)}#{line_postfix}\n" + formatted_deps.join("\n")
end

#list_recent_output(saved_stdout_folder, saved_stdout_glob, list_count) ⇒ Object

:reek:UtilityFunction



89
90
91
92
93
# File 'lib/markdown_exec.rb', line 89

def list_recent_output(saved_stdout_folder, saved_stdout_glob,
                       list_count)
  SavedFilesMatcher.most_recent_list(saved_stdout_folder,
                                     saved_stdout_glob, list_count)
end

#list_recent_scripts(saved_script_folder, saved_script_glob, list_count) ⇒ Object

:reek:UtilityFunction



96
97
98
99
100
# File 'lib/markdown_exec.rb', line 96

def list_recent_scripts(saved_script_folder, saved_script_glob,
                        list_count)
  SavedFilesMatcher.most_recent_list(saved_script_folder,
                                     saved_script_glob, list_count)
end

#mainObject

MDE.prepend(ImwUx)



223
224
225
226
227
228
229
230
231
232
# File 'lib/input_sequencer.rb', line 223

def main
  if ARGV.empty?
    puts "Usage: #{__FILE__} document_filename [block_name...]"
    exit(1)
  end
  document_filename = ARGV.shift
  initial_blocks = ARGV
  mde = MDE.new(document_filename, initial_blocks)
  mde.do_run
end


22
23
24
# File 'lib/shared.rb', line 22

def menu_from_yaml
  YAML.load File.open(File.join(File.expand_path(__dir__), LOCAL_YML))
end

#rbiObject



57
58
59
60
# File 'lib/markdown_exec.rb', line 57

def rbi
  pp(caller.take(4).map.with_index { |line, ind| "   - #{ind}: #{line}" })
  binding.irb
end

#rbpObject



62
63
64
65
66
# File 'lib/markdown_exec.rb', line 62

def rbp
  rpry
  pp(caller.take(4).map.with_index { |line, ind| "   - #{ind}: #{line}" })
  binding.pry
end

#rpryObject



74
75
76
77
# File 'lib/markdown_exec.rb', line 74

def rpry
  require 'pry-nav'
  require 'pry-stack_explorer'
end

#spec_source(file, env_var_name = 'SPEC_DEBUG') ⇒ Object

output standard header for file load during testing



5
6
7
8
9
10
# File 'lib/rspec_helpers.rb', line 5

def spec_source(file, env_var_name = 'SPEC_DEBUG')
  if (->(val) { val.nil? ? false : !(val.empty? || val == '0') })
     .call(ENV.fetch(env_var_name, nil))
    puts "#{env_var_name}: #{file}"
  end
end