Class: Lmt::Tangle

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging, Methadone::Main
Defined in:
lib/lmt/lmt.rb

Defined Under Namespace

Classes: Context, Filter, LineFilter, Tangler

Class Method Summary collapse

Class Method Details

.check_argumentsObject



416
417
418
419
420
421
422
423
# File 'lib/lmt/lmt.rb', line 416

def self.check_arguments
  missing = @required_options.select{ |p| options[p].nil?}
  unless missing.empty?
    message = "Missing Required Argument(s): #{missing.join(', ')}"

    abort("#{message}\n\n#{opts.help()}")
  end
end

.extract_causes(error) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/lmt/lmt.rb', line 34

def self.extract_causes(error)
  if (error.cause)
    "  Caused by: #{error.cause.message}\n#{extract_causes(error.cause)}"
  else
    ""
  end
end

.report_self_test_failure(message) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/lmt/lmt.rb', line 99

def self.report_self_test_failure(message)
  if @dev
    p message
  else
    throw message
  end
end

.required(*options) ⇒ Object



412
413
414
# File 'lib/lmt/lmt.rb', line 412

def self.required(*options)
  @required_options = options
end

.self_testObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/lmt/lmt.rb', line 42

def self.self_test()
  
  block_replacement = true
  replaced_block = false
  block_appendment = false
  
  # this is the replacement
  replaced_block = true
  # Yay appended code gets injected
  block_appendment = true
  insertion_works_with_spaces = false
  insertion_works_with_spaces = true
  escaped_string = '⦅macro_description⦆'
  # These require the code in the macro to work.
  report_self_test_failure("block replacement doesn't work") unless block_replacement and replaced_block
  report_self_test_failure("appending to macros doesn't work") unless block_appendment
  report_self_test_failure("insertion must support spaces") unless insertion_works_with_spaces
  report_self_test_failure("double parentheses may be escaped") unless escaped_string[0] != '\\'
  two_macros = "foo foo"
  report_self_test_failure("Should be able to place two macros on the same line") unless two_macros == "foo foo"
  string_with_backslash = "this string ends in \\."
  report_self_test_failure("ruby escape doesn't escape backslash") unless string_with_backslash =~ /\\.?/
  some_text = "some text"
  report_self_test_failure("Double quote doesn't double quote") unless some_text == "some text"
  some_indented_text = "  some text"
  report_self_test_failure("Indent lines should add two spaces to lines") unless some_indented_text == "  some text"
  items = ["item 1",
    "item 2",]
  report_self_test_failure("Add comma isn't adding commas") unless items == ["item 1", "item 2"]
  included_string = "I came from lmt_include.lmd"
  report_self_test_failure("included replacements should replace blocks") unless included_string == "I came from lmt_include.lmd"
  
  from_extension = true

  report_self_test_failure("extension hook should be able to add blocks") unless from_extension
  conditional_output_else = true
  conditional_output_elsif = true
  report_self_test_failure("conditional output elseif should not be output when elseif is false") unless conditional_output_elsif
  report_self_test_failure("conditional output else should not be output when if true") unless conditional_output_else
  conditional_output_else = true
  conditional_output_elsif = true
  report_self_test_failure("conditional output elsif should not be output even if true when is also true") unless conditional_output_elsif
  report_self_test_failure("conditional output else should not be output when if is true (if and elseif)") unless conditional_output_else
  conditional_output_if = true
  conditional_output_else = true
  conditional_output_elsif = true
  report_self_test_failure("conditional output if should not be output when false") unless conditional_output_if
  report_self_test_failure("conditional output elseif should be output when elseif is true") unless conditional_output_elsif
  report_self_test_failure("conditional output else should not be output when elseif is true") unless conditional_output_else
  conditional_output_if = true
  conditional_output_elsif = true
  conditional_output_else = true
  report_self_test_failure("conditional output if should not be output when false") unless conditional_output_if
  report_self_test_failure("conditional output elseif should not be output when elseif is false") unless conditional_output_elsif
  report_self_test_failure("conditional output else should be output when neither if nor elseif is true") unless conditional_output_else
end