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.



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

def initialize(command_class)
  @command_class = command_class
end

Instance Method Details

#commands_for_thor_class(thor_class) ⇒ Object



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

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



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

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

#descript_lines_for_class(thor_class) ⇒ Object



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

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

#get_bindingsObject

rubocop:disable Style/AccessorMethodName



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

def get_bindings # rubocop:disable Style/AccessorMethodName
  binding
end

#subcommands_with_commandsObject



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

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



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

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



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

def top_level_commands
  commands_for_thor_class(@command_class)
end

#top_level_commands_with_descriptionsObject



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

def top_level_commands_with_descriptions
  descript_lines_for_class(@command_class)
end