Module: Rundoc

Extended by:
Rundoc
Included in:
Rundoc
Defined in:
lib/rundoc.rb,
lib/rundoc/cli.rb,
lib/rundoc/version.rb,
lib/rundoc/document.rb,
lib/rundoc/peg_parser.rb,
lib/rundoc/peg_parser.rb,
lib/rundoc/code_command.rb,
lib/rundoc/code_command/raw.rb,
lib/rundoc/code_command/pipe.rb,
lib/rundoc/context/execution.rb,
lib/rundoc/fenced_code_block.rb,
lib/rundoc/code_command/write.rb,
lib/rundoc/cli_argument_parser.rb,
lib/rundoc/context/after_build.rb,
lib/rundoc/code_command/deferred.rb,
lib/rundoc/code_command/rundoc_command.rb,
lib/rundoc/code_command/no_such_command.rb

Defined Under Namespace

Modules: CodeCommand, Context Classes: CLI, CLIArgumentParser, Document, FencedCodeBlock, PegParser, PegTransformer, UnknownCommand

Constant Summary collapse

VERSION =
"5.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#project_rootObject

Returns the value of attribute project_root.



114
115
116
# File 'lib/rundoc.rb', line 114

def project_root
  @project_root
end

Instance Method Details

#after_build(&block) ⇒ Object



91
92
93
94
# File 'lib/rundoc.rb', line 91

def after_build(&block)
  @after_build_block ||= []
  @after_build_block << block
end

#always_hidden_commandsObject



78
79
80
# File 'lib/rundoc.rb', line 78

def always_hidden_commands
  @always_hidden_commands ||= {}
end

#code_command(keyword) ⇒ Object



64
65
66
# File 'lib/rundoc.rb', line 64

def code_command(keyword)
  user_args[:"#{keyword}"]
end

#code_command_from_keyword(keyword, args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rundoc.rb', line 10

def code_command_from_keyword(keyword, args)
  args_klass = code_command(keyword.to_sym)
  original_args = args&.dup

  if args_klass
    runner_klass = user_args_runner[keyword]

    if args.is_a?(Array) && args.last.is_a?(Hash)
      kwargs = args.pop
      user_args = args_klass.new(*args, **kwargs)
    elsif args.is_a?(Hash)
      user_args = args_klass.new(**args)
    else
      user_args = args_klass.new(*args)
    end
  elsif keyword.start_with?("#")
    args_klass = Rundoc::CodeCommand::CommentArgs
    runner_klass = Rundoc::CodeCommand::CommentRunner
    remainder = keyword.to_s.delete_prefix("#")
    comment_text = [remainder, args].compact.join(" ").strip
    user_args = args_klass.new(comment_text.empty? ? nil : comment_text)
  else
    runner_klass = Rundoc::CodeCommand::NoSuchCommand
    user_args = nil
  end

  deferred = CodeCommand::Deferred.new(
    args_instance: user_args,
    runner_klass: runner_klass,
    always_hidden: always_hidden_commands[keyword] || keyword.start_with?("#")
  )
  deferred.original_args = original_args
  deferred.keyword = keyword
  deferred
rescue ArgumentError => e
  raise ArgumentError, "Wrong method signature for #{keyword} with arguments: #{original_args.inspect}, error:\n #{e.message}"
end

#config {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Rundoc)

    the object that the method was called on



96
97
98
# File 'lib/rundoc.rb', line 96

def config
  yield self
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Rundoc)

    the object that the method was called on



82
83
84
# File 'lib/rundoc.rb', line 82

def configure(&block)
  yield self
end

#filter_sensitive(sensitive) ⇒ Object



100
101
102
103
104
# File 'lib/rundoc.rb', line 100

def filter_sensitive(sensitive)
  raise "Expecting #{sensitive} to be a hash" unless sensitive.is_a?(Hash)
  @sensitive ||= {}
  @sensitive.merge!(sensitive)
end

#known_commandsObject



68
69
70
# File 'lib/rundoc.rb', line 68

def known_commands
  user_args.keys
end

#parser_optionsObject



52
53
54
# File 'lib/rundoc.rb', line 52

def parser_options
  @parser_options ||= {}
end

#register_code_command(keyword:, args_klass:, runner_klass:, always_hidden: false) ⇒ Object



72
73
74
75
76
# File 'lib/rundoc.rb', line 72

def register_code_command(keyword:, args_klass:, runner_klass:, always_hidden: false)
  user_args[keyword] = args_klass
  user_args_runner[keyword] = runner_klass
  always_hidden_commands[keyword] = always_hidden
end

#run_after_build(context) ⇒ Object



86
87
88
89
# File 'lib/rundoc.rb', line 86

def run_after_build(context)
  @after_build_block ||= []
  @after_build_block.each { |block| block.call(context) }
end

#sanitize!(doc) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/rundoc.rb', line 106

def sanitize!(doc)
  return doc if @sensitive.nil?
  @sensitive.each do |sensitive, replace|
    doc.gsub!(sensitive.to_s, replace)
  end
  doc
end

#user_argsObject



60
61
62
# File 'lib/rundoc.rb', line 60

def user_args
  @user_args ||= {}
end

#user_args_runnerObject



56
57
58
# File 'lib/rundoc.rb', line 56

def user_args_runner
  @user_args_runner ||= {}
end

#user_code_runner_klassObject



48
49
50
# File 'lib/rundoc.rb', line 48

def user_code_runner_klass
  @user_code_runner_klass ||= {}
end