Class: ParameterExpansion
Overview
Parameter expansion utility for markdown_exec Handles different invocation types for parameter substitution
Defined Under Namespace
Classes: NewVariable
Class Method Summary collapse
-
.expand_parameter(param, invocation, value, unique: nil) ⇒ Array
REQ-001: Expands a parameter based on invocation type and value ARCH-003: Template method pattern - delegates to specific handlers.
-
.expand_parameter_string(param, invocation, value, unique: rand(1e4)) ⇒ Object
Convenience method that returns just the expansion string (backward compatibility).
-
.expand_parameters(parameter_hash, unique: rand(1e4)) ⇒ Object
Process multiple parameters and collect all new variables.
Class Method Details
.expand_parameter(param, invocation, value, unique: nil) ⇒ Array
REQ-001: Expands a parameter based on invocation type and value ARCH-003: Template method pattern - delegates to specific handlers
Invocation codes:
-
First letter: Input type (C=command, E=expression, L=literal, V=variable)
-
Second letter: Output type (C=command, E=expression, L=literal, V=variable) If second letter is missing, defaults to Q (literal)
Examples:
("PARAM", "cc", "ls -la")
# => ["ls -la", nil] (command as command)
("PARAM", "ce", "ls -la")
# => ["${PARAM}", NewVariable object] (command as expression)
("PARAM", "ll", "hello world")
# => ["hello world", nil] (literal as literal)
("PARAM", "c", "ls -la")
# => ["ls -la", nil] (command as literal, defaults to Q)
("PARAM", "e", "hello world")
# => ["hello world", nil] (expression as literal, defaults to Q)
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/parameter_expansion.rb', line 351 def self.(param, invocation, value, unique: nil) return [value, nil] if invocation.nil? || invocation.empty? # unique = rand(1e4) if unique.nil? if unique.nil? # unique from a global counter @@unique ||= 0 @@unique += 1 unique = @@unique end input_type = invocation[0]&.upcase output_type = invocation[1]&.upcase || 'Q' # Default to Q if second character missing ww 'input_type:', input_type ww 'output_type:', output_type # ARCH-001: Strategy pattern for input type handling case input_type when 'C' # IMPL-001: Command substitution (param, output_type, value, invocation, unique: unique) when 'E' # IMPL-002: Evaluated expression (param, output_type, value, invocation, unique: unique) when 'L', 'Q' # REQ-004: Literal (accept both L and Q for backward compatibility) (param, output_type, value, invocation, unique: unique) when 'V' # IMPL-004: Variable reference (param, output_type, value, invocation) else # Default to raw literal if no valid input type [value, nil] end end |
.expand_parameter_string(param, invocation, value, unique: rand(1e4)) ⇒ Object
Convenience method that returns just the expansion string (backward compatibility)
384 385 386 387 |
# File 'lib/parameter_expansion.rb', line 384 def self.(param, invocation, value, unique: rand(1e4)) result, _new_var = (param, invocation, value, unique: unique) result end |
.expand_parameters(parameter_hash, unique: rand(1e4)) ⇒ Object
Process multiple parameters and collect all new variables
390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/parameter_expansion.rb', line 390 def self.(parameter_hash, unique: rand(1e4)) expansions = {} new_variables = [] parameter_hash.each do |param, (invocation, value)| expansion, new_var = (param, invocation, value, unique: unique) expansions[param] = expansion new_variables << new_var if new_var end [expansions, new_variables] end |