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.
-
#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
18 19 20 21 22 |
# File 'lib/reviewer/command/string.rb', line 18 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.
10 11 12 |
# File 'lib/reviewer/command/string.rb', line 10 def command_type @command_type end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
10 11 12 |
# File 'lib/reviewer/command/string.rb', line 10 def files @files end |
#tool_settings ⇒ Object (readonly)
Returns the value of attribute tool_settings.
10 11 12 |
# File 'lib/reviewer/command/string.rb', line 10 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.
55 56 57 |
# File 'lib/reviewer/command/string.rb', line 55 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
49 |
# File 'lib/reviewer/command/string.rb', line 49 def env_variables = Env.new(tool_settings.env).to_s |
#files_string ⇒ String?
Builds the files portion of the command string
73 74 75 76 77 78 79 80 |
# File 'lib/reviewer/command/string.rb', line 73 def files_string return nil unless files_applicable? file_list = files.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
1. The `review` commands are the only commands that use flags
2. If no flags are configured, this won't do anything
64 65 66 67 68 |
# File 'lib/reviewer/command/string.rb', line 64 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
37 38 39 40 41 42 43 44 |
# File 'lib/reviewer/command/string.rb', line 37 def to_a [ env_variables, body, flags, files_string ].compact end |
#to_s ⇒ String
Converts the command to a complete string ready for execution
27 28 29 30 31 32 |
# File 'lib/reviewer/command/string.rb', line 27 def to_s to_a .map(&:strip) # Remove extra spaces on the components .join(' ') # Merge the components .strip # Strip extra spaces from the end result end |