Class: Inspec::EnvPrinter::TemplateContext

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/env_printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(command_class) ⇒ TemplateContext

Returns a new instance of TemplateContext.



107
108
109
# File 'lib/inspec/env_printer.rb', line 107

def initialize(command_class)
  @command_class = command_class
end

Instance Method Details

#commands_for_thor_class(thor_class) ⇒ Object



143
144
145
# File 'lib/inspec/env_printer.rb', line 143

def commands_for_thor_class(thor_class)
  thor_class.all_commands.values.map { |c| c.usage.split.first }
end

#descript_line_for_command(c) ⇒ Object



151
152
153
# File 'lib/inspec/env_printer.rb', line 151

def descript_line_for_command(c)
  "#{c.usage.split.first}:#{Shellwords.escape(c.description)}"
end

#descript_lines_for_class(thor_class) ⇒ Object



147
148
149
# File 'lib/inspec/env_printer.rb', line 147

def descript_lines_for_class(thor_class)
  thor_class.all_commands.values.map { |c| descript_line_for_command(c) }
end

#get_bindingsObject

rubocop:disable Naming/AccessorMethodName



111
112
113
# File 'lib/inspec/env_printer.rb', line 111

def get_bindings # rubocop:disable Naming/AccessorMethodName
  binding
end

#subcommands_with_commandsObject



127
128
129
130
131
132
133
# File 'lib/inspec/env_printer.rb', line 127

def subcommands_with_commands
  ret = {}
  @command_class.subcommand_classes.each do |k, v|
    ret[k] = commands_for_thor_class(v)
  end
  ret
end

#subcommands_with_commands_and_descriptionsObject



135
136
137
138
139
140
141
# File 'lib/inspec/env_printer.rb', line 135

def subcommands_with_commands_and_descriptions
  ret = {}
  @command_class.subcommand_classes.each do |k, v|
    ret[k] = descript_lines_for_class(v)
  end
  ret
end

#top_level_commandsObject

The following functions all assume that @command_class is something that provides a Thor-like API



119
120
121
# File 'lib/inspec/env_printer.rb', line 119

def top_level_commands
  commands_for_thor_class(@command_class)
end

#top_level_commands_with_descriptionsObject



123
124
125
# File 'lib/inspec/env_printer.rb', line 123

def top_level_commands_with_descriptions
  descript_lines_for_class(@command_class)
end