Class: Makit::Commands::Factory
- Inherits:
-
Object
- Object
- Makit::Commands::Factory
- Defined in:
- lib/makit/commands/factory.rb
Overview
Factory for creating common command requests.
This factory provides convenient methods for creating Request objects for common operations like git commands, bundle operations, rake tasks, and system utilities.
Class Method Summary collapse
-
.bundle_exec(command_string, directory = Dir.pwd, **options) ⇒ Request
Create a bundle exec request.
-
.bundle_install(directory = Dir.pwd, **options) ⇒ Request
Create a bundle install request.
-
.dotnet_command(subcommand, directory = Dir.pwd, **options) ⇒ Request
Create a dotnet CLI request.
-
.gem_build(gemspec_file = nil, directory = Dir.pwd, **options) ⇒ Request
Create a gem build request.
-
.gem_install(gem_name, **options) ⇒ Request
Create a gem install request.
-
.git_clone(repository_url, target_directory = nil, **options) ⇒ Request
Create a git clone request.
-
.git_log(directory = Dir.pwd, **options) ⇒ Request
Create a git log request.
-
.git_pull(directory = Dir.pwd, **options) ⇒ Request
Create a git pull request.
-
.git_status(directory = Dir.pwd, **options) ⇒ Request
Create a git status request.
-
.npm_command(subcommand, directory = Dir.pwd, **options) ⇒ Request
Create a Node.js/npm command request.
-
.rake_task(task_name, directory = Dir.pwd, **options) ⇒ Request
Create a rake task request.
-
.ruby_script(script_file, directory = Dir.pwd, **options) ⇒ Request
Create a Ruby script execution request.
-
.system_command(command, arguments = [], **options) ⇒ Request
Create a system command request with validation.
Class Method Details
.bundle_exec(command_string, directory = Dir.pwd, **options) ⇒ Request
Create a bundle exec request.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/makit/commands/factory.rb', line 158 def self.bundle_exec(command_string, directory = Dir.pwd, **) # Parse the command string to get command and arguments parts = command_string.strip.split(/\s+/) arguments = ["exec"] + parts Request.new( command: "bundle", arguments: arguments, directory: directory, timeout: .fetch(:timeout, 120), metadata: { operation: "bundle_exec", exec_command: command_string, }.merge(.fetch(:metadata, {})), ) end |
.bundle_install(directory = Dir.pwd, **options) ⇒ Request
Create a bundle install request.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/makit/commands/factory.rb', line 131 def self.bundle_install(directory = Dir.pwd, **) arguments = ["install"] arguments.push("--jobs", [:jobs].to_s) if [:jobs] arguments.push("--path", [:path]) if [:path] arguments << "--deployment" if [:deployment] Request.new( command: "bundle", arguments: arguments, directory: directory, timeout: .fetch(:timeout, 300), metadata: { operation: "bundle_install", jobs: [:jobs], path: [:path], deployment: [:deployment], }.merge(.fetch(:metadata, {})), ) end |
.dotnet_command(subcommand, directory = Dir.pwd, **options) ⇒ Request
Create a dotnet CLI request.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/makit/commands/factory.rb', line 314 def self.dotnet_command(subcommand, directory = Dir.pwd, **) arguments = [subcommand] arguments.concat([:arguments]) if [:arguments] arguments.push("--configuration", [:configuration]) if [:configuration] arguments.push("--framework", [:framework]) if [:framework] Request.new( command: "dotnet", arguments: arguments, directory: directory, timeout: .fetch(:timeout, 300), metadata: { operation: "dotnet_#{subcommand}", subcommand: subcommand, configuration: [:configuration], framework: [:framework], }.merge(.fetch(:metadata, {})), ) end |
.gem_build(gemspec_file = nil, directory = Dir.pwd, **options) ⇒ Request
Create a gem build request.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/makit/commands/factory.rb', line 209 def self.gem_build(gemspec_file = nil, directory = Dir.pwd, **) arguments = ["build"] arguments << gemspec_file if gemspec_file Request.new( command: "gem", arguments: arguments, directory: directory, timeout: .fetch(:timeout, 120), metadata: { operation: "gem_build", gemspec: gemspec_file, }.merge(.fetch(:metadata, {})), ) end |
.gem_install(gem_name, **options) ⇒ Request
Create a gem install request.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/makit/commands/factory.rb', line 234 def self.gem_install(gem_name, **) arguments = ["install", gem_name] arguments.push("--version", [:version]) if [:version] arguments << "--local" if [:local] arguments.push("--source", [:source]) if [:source] Request.new( command: "gem", arguments: arguments, timeout: .fetch(:timeout, 180), metadata: { operation: "gem_install", gem: gem_name, version: [:version], local: [:local], source: [:source], }.merge(.fetch(:metadata, {})), ) end |
.git_clone(repository_url, target_directory = nil, **options) ⇒ Request
Create a git clone request.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/makit/commands/factory.rb', line 29 def self.git_clone(repository_url, target_directory = nil, **) arguments = ["clone", repository_url] arguments << target_directory if target_directory Request.new( command: "git", arguments: arguments, timeout: .fetch(:timeout, 300), metadata: { operation: "git_clone", repository: repository_url, target: target_directory, }.merge(.fetch(:metadata, {})), ) end |
.git_log(directory = Dir.pwd, **options) ⇒ Request
Create a git log request.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/makit/commands/factory.rb', line 103 def self.git_log(directory = Dir.pwd, **) arguments = ["log"] arguments.push("-n", [:limit].to_s) if [:limit] arguments.push("--format", [:format]) if [:format] arguments.push("--since", [:since]) if [:since] Request.new( command: "git", arguments: arguments, directory: directory, metadata: { operation: "git_log", limit: [:limit], format: [:format], since: [:since], }.merge(.fetch(:metadata, {})), ) end |
.git_pull(directory = Dir.pwd, **options) ⇒ Request
Create a git pull request.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/makit/commands/factory.rb', line 53 def self.git_pull(directory = Dir.pwd, **) arguments = ["pull"] arguments << [:remote] if [:remote] arguments << [:branch] if [:branch] Request.new( command: "git", arguments: arguments, directory: directory, timeout: .fetch(:timeout, 120), metadata: { operation: "git_pull", remote: [:remote] || "origin", branch: [:branch], }.merge(.fetch(:metadata, {})), ) end |
.git_status(directory = Dir.pwd, **options) ⇒ Request
Create a git status request.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/makit/commands/factory.rb', line 78 def self.git_status(directory = Dir.pwd, **) arguments = ["status"] arguments << "--porcelain" if [:porcelain] arguments << "--short" if [:short] Request.new( command: "git", arguments: arguments, directory: directory, metadata: { operation: "git_status", porcelain: [:porcelain], short: [:short], }.merge(.fetch(:metadata, {})), ) end |
.npm_command(subcommand, directory = Dir.pwd, **options) ⇒ Request
Create a Node.js/npm command request.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/makit/commands/factory.rb', line 342 def self.npm_command(subcommand, directory = Dir.pwd, **) arguments = [subcommand] arguments.concat([:arguments]) if [:arguments] Request.new( command: "npm", arguments: arguments, directory: directory, timeout: .fetch(:timeout, 300), metadata: { operation: "npm_#{subcommand}", subcommand: subcommand, }.merge(.fetch(:metadata, {})), ) end |
.rake_task(task_name, directory = Dir.pwd, **options) ⇒ Request
Create a rake task request.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/makit/commands/factory.rb', line 184 def self.rake_task(task_name, directory = Dir.pwd, **) arguments = [task_name] arguments.concat([:arguments]) if [:arguments] Request.new( command: "rake", arguments: arguments, directory: directory, environment: [:environment] || {}, timeout: .fetch(:timeout, 300), metadata: { operation: "rake_task", task: task_name, arguments: [:arguments], }.merge(.fetch(:metadata, {})), ) end |
.ruby_script(script_file, directory = Dir.pwd, **options) ⇒ Request
Create a Ruby script execution request.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/makit/commands/factory.rb', line 263 def self.ruby_script(script_file, directory = Dir.pwd, **) arguments = [script_file] arguments.concat([:arguments]) if [:arguments] Request.new( command: "ruby", arguments: arguments, directory: directory, environment: [:environment] || {}, timeout: .fetch(:timeout, 120), metadata: { operation: "ruby_script", script: script_file, arguments: [:arguments], }.merge(.fetch(:metadata, {})), ) end |
.system_command(command, arguments = [], **options) ⇒ Request
Create a system command request with validation.
290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/makit/commands/factory.rb', line 290 def self.system_command(command, arguments = [], **) Request.new( command: command, arguments: Array(arguments), directory: [:directory] || Dir.pwd, environment: [:environment] || {}, timeout: .fetch(:timeout, 60), metadata: { operation: "system_command", system_command: command, }.merge(.fetch(:metadata, {})), ) end |