Class: Reviewer::Command::String
- Inherits:
-
Object
- Object
- Reviewer::Command::String
- Defined in:
- lib/reviewer/command/string.rb,
lib/reviewer/command/string/env.rb,
lib/reviewer/command/string/flags.rb
Overview
Assembles tool tool_settings into a usable command string for the command type
Defined Under Namespace
Instance Attribute Summary collapse
-
#command_type ⇒ Object
readonly
Returns the value of attribute command_type.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#tool_settings ⇒ Object
readonly
Returns the value of attribute tool_settings.
Instance Method Summary collapse
-
#body ⇒ String
The base command string from the tool's configuration.
-
#env_variables ⇒ String
The string of environment variables built from a tool's configuration settings.
-
#files_string ⇒ String?
Builds the files portion of the command string with each path escaped for shell execution.
-
#flags ⇒ String
Gets the flags to be used in conjunction with the review command for a tool 1.
-
#initialize(command_type, tool_settings:, files: []) ⇒ String
constructor
Creates a command string builder for a tool.
-
#to_a ⇒ Array<String, nil>
Converts the command to an array of its components.
-
#to_s ⇒ String
Converts the command to a complete string ready for execution.
Constructor Details
#initialize(command_type, tool_settings:, files: []) ⇒ String
Creates a command string builder for a tool
20 21 22 23 24 |
# File 'lib/reviewer/command/string.rb', line 20 def initialize(command_type, tool_settings:, files: []) @command_type = command_type @tool_settings = tool_settings @files = Array(files) end |
Instance Attribute Details
#command_type ⇒ Object (readonly)
Returns the value of attribute command_type.
12 13 14 |
# File 'lib/reviewer/command/string.rb', line 12 def command_type @command_type end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
12 13 14 |
# File 'lib/reviewer/command/string.rb', line 12 def files @files end |
#tool_settings ⇒ Object (readonly)
Returns the value of attribute tool_settings.
12 13 14 |
# File 'lib/reviewer/command/string.rb', line 12 def tool_settings @tool_settings end |
Instance Method Details
#body ⇒ String
The base command string from the tool's configuration. Uses the file-scoped command when files are present and one is configured.
56 57 58 |
# File 'lib/reviewer/command/string.rb', line 56 def body file_scoped_command || tool_settings.commands.fetch(command_type) end |
#env_variables ⇒ String
The string of environment variables built from a tool's configuration settings
50 |
# File 'lib/reviewer/command/string.rb', line 50 def env_variables = Env.new(tool_settings.env).to_s |
#files_string ⇒ String?
Builds the files portion of the command string with each path escaped for shell execution
74 75 76 77 78 79 80 81 82 |
# File 'lib/reviewer/command/string.rb', line 74 def files_string return nil unless files_applicable? file_list = files.map { |file| Shellwords.shellescape(file) } .join(tool_settings.files_separator) flag = tool_settings.files_flag flag.empty? ? file_list : "#{flag} #{file_list}" end |
#flags ⇒ String
Gets the flags to be used in conjunction with the review command for a tool
- The
reviewcommands are the only commands that use flags - If no flags are configured, this won't do anything
65 66 67 68 69 |
# File 'lib/reviewer/command/string.rb', line 65 def flags return nil unless flags? Flags.new(tool_settings.flags).to_s end |
#to_a ⇒ Array<String, nil>
Converts the command to an array of its components
38 39 40 41 42 43 44 45 |
# File 'lib/reviewer/command/string.rb', line 38 def to_a [ env_variables, body, flags, files_string ].compact end |
#to_s ⇒ String
Converts the command to a complete string ready for execution
29 30 31 32 33 |
# File 'lib/reviewer/command/string.rb', line 29 def to_s components = [env_variables, body, flags].compact.map(&:strip).reject(&:empty?) components << files_string if files_string components.join(' ') end |