Class: Makit::Commands::Factory

Inherits:
Object
  • Object
show all
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.

Examples:

Creating git commands

request = Factory.git_clone("https://github.com/user/repo.git", "/path/to/clone")
request = Factory.git_status("/path/to/repo")

Creating Ruby commands

request = Factory.bundle_install("/path/to/project")
request = Factory.rake_task("test", "/path/to/project")

Class Method Summary collapse

Class Method Details

.bundle_exec(command_string, directory = Dir.pwd, **options) ⇒ Request

Create a bundle exec request.

Parameters:

  • command_string (String)

    command to execute with bundle exec

  • directory (String) (defaults to: Dir.pwd)

    project directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :timeout (Integer) — default: 120

    timeout in seconds

Returns:

  • (Request)

    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, **options)
  # 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: options.fetch(:timeout, 120),
    metadata: {
      operation: "bundle_exec",
      exec_command: command_string,
    }.merge(options.fetch(:metadata, {})),
  )
end

.bundle_install(directory = Dir.pwd, **options) ⇒ Request

Create a bundle install request.

Parameters:

  • directory (String) (defaults to: Dir.pwd)

    project directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :jobs (Integer) — default: nil

    number of parallel jobs

  • :path (String) — default: nil

    install path

  • :deployment (Boolean) — default: false

    deployment mode

  • :timeout (Integer) — default: 300

    timeout in seconds

Returns:

  • (Request)

    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, **options)
  arguments = ["install"]
  arguments.push("--jobs", options[:jobs].to_s) if options[:jobs]
  arguments.push("--path", options[:path]) if options[:path]
  arguments << "--deployment" if options[:deployment]

  Request.new(
    command: "bundle",
    arguments: arguments,
    directory: directory,
    timeout: options.fetch(:timeout, 300),
    metadata: {
      operation: "bundle_install",
      jobs: options[:jobs],
      path: options[:path],
      deployment: options[:deployment],
    }.merge(options.fetch(:metadata, {})),
  )
end

.dotnet_command(subcommand, directory = Dir.pwd, **options) ⇒ Request

Create a dotnet CLI request.

Parameters:

  • subcommand (String)

    dotnet subcommand (build, test, run, etc.)

  • directory (String) (defaults to: Dir.pwd)

    project directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :arguments (Array<String>)

    additional arguments

  • :configuration (String) — default: nil

    build configuration

  • :framework (String) — default: nil

    target framework

  • :timeout (Integer) — default: 300

    timeout in seconds

Returns:



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, **options)
  arguments = [subcommand]
  arguments.concat(options[:arguments]) if options[:arguments]
  arguments.push("--configuration", options[:configuration]) if options[:configuration]
  arguments.push("--framework", options[:framework]) if options[:framework]

  Request.new(
    command: "dotnet",
    arguments: arguments,
    directory: directory,
    timeout: options.fetch(:timeout, 300),
    metadata: {
      operation: "dotnet_#{subcommand}",
      subcommand: subcommand,
      configuration: options[:configuration],
      framework: options[:framework],
    }.merge(options.fetch(:metadata, {})),
  )
end

.gem_build(gemspec_file = nil, directory = Dir.pwd, **options) ⇒ Request

Create a gem build request.

Parameters:

  • gemspec_file (String, nil) (defaults to: nil)

    gemspec file (optional, will auto-detect)

  • directory (String) (defaults to: Dir.pwd)

    project directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :timeout (Integer) — default: 120

    timeout in seconds

Returns:



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, **options)
  arguments = ["build"]
  arguments << gemspec_file if gemspec_file

  Request.new(
    command: "gem",
    arguments: arguments,
    directory: directory,
    timeout: options.fetch(:timeout, 120),
    metadata: {
      operation: "gem_build",
      gemspec: gemspec_file,
    }.merge(options.fetch(:metadata, {})),
  )
end

.gem_install(gem_name, **options) ⇒ Request

Create a gem install request.

Parameters:

  • gem_name (String)

    gem name or gem file

  • options (Hash)

    additional options

Options Hash (**options):

  • :version (String)

    specific version

  • :local (Boolean) — default: false

    install from local file

  • :source (String)

    gem source

  • :timeout (Integer) — default: 180

    timeout in seconds

Returns:

  • (Request)

    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, **options)
  arguments = ["install", gem_name]
  arguments.push("--version", options[:version]) if options[:version]
  arguments << "--local" if options[:local]
  arguments.push("--source", options[:source]) if options[:source]

  Request.new(
    command: "gem",
    arguments: arguments,
    timeout: options.fetch(:timeout, 180),
    metadata: {
      operation: "gem_install",
      gem: gem_name,
      version: options[:version],
      local: options[:local],
      source: options[:source],
    }.merge(options.fetch(:metadata, {})),
  )
end

.git_clone(repository_url, target_directory = nil, **options) ⇒ Request

Create a git clone request.

Parameters:

  • repository_url (String)

    git repository URL

  • target_directory (String, nil) (defaults to: nil)

    target directory (optional)

  • options (Hash)

    additional options

Options Hash (**options):

  • :timeout (Integer) — default: 300

    timeout in seconds

  • :metadata (Hash)

    additional metadata

Returns:



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, **options)
  arguments = ["clone", repository_url]
  arguments << target_directory if target_directory

  Request.new(
    command: "git",
    arguments: arguments,
    timeout: options.fetch(:timeout, 300),
    metadata: {
      operation: "git_clone",
      repository: repository_url,
      target: target_directory,
    }.merge(options.fetch(:metadata, {})),
  )
end

.git_log(directory = Dir.pwd, **options) ⇒ Request

Create a git log request.

Parameters:

  • directory (String) (defaults to: Dir.pwd)

    repository directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :limit (Integer) — default: nil

    limit number of commits

  • :format (String) — default: nil

    log format

  • :since (String) — default: nil

    since date/commit

Returns:



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, **options)
  arguments = ["log"]
  arguments.push("-n", options[:limit].to_s) if options[:limit]
  arguments.push("--format", options[:format]) if options[:format]
  arguments.push("--since", options[:since]) if options[:since]

  Request.new(
    command: "git",
    arguments: arguments,
    directory: directory,
    metadata: {
      operation: "git_log",
      limit: options[:limit],
      format: options[:format],
      since: options[:since],
    }.merge(options.fetch(:metadata, {})),
  )
end

.git_pull(directory = Dir.pwd, **options) ⇒ Request

Create a git pull request.

Parameters:

  • directory (String) (defaults to: Dir.pwd)

    repository directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :remote (String) — default: "origin"

    remote name

  • :branch (String) — default: nil

    specific branch

  • :timeout (Integer) — default: 120

    timeout in seconds

Returns:



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, **options)
  arguments = ["pull"]
  arguments << options[:remote] if options[:remote]
  arguments << options[:branch] if options[:branch]

  Request.new(
    command: "git",
    arguments: arguments,
    directory: directory,
    timeout: options.fetch(:timeout, 120),
    metadata: {
      operation: "git_pull",
      remote: options[:remote] || "origin",
      branch: options[:branch],
    }.merge(options.fetch(:metadata, {})),
  )
end

.git_status(directory = Dir.pwd, **options) ⇒ Request

Create a git status request.

Parameters:

  • directory (String) (defaults to: Dir.pwd)

    repository directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :porcelain (Boolean) — default: false

    use porcelain format

  • :short (Boolean) — default: false

    use short format

Returns:



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, **options)
  arguments = ["status"]
  arguments << "--porcelain" if options[:porcelain]
  arguments << "--short" if options[:short]

  Request.new(
    command: "git",
    arguments: arguments,
    directory: directory,
    metadata: {
      operation: "git_status",
      porcelain: options[:porcelain],
      short: options[:short],
    }.merge(options.fetch(:metadata, {})),
  )
end

.npm_command(subcommand, directory = Dir.pwd, **options) ⇒ Request

Create a Node.js/npm command request.

Parameters:

  • subcommand (String)

    npm subcommand (install, test, run, etc.)

  • directory (String) (defaults to: Dir.pwd)

    project directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :arguments (Array<String>)

    additional arguments

  • :timeout (Integer) — default: 300

    timeout in seconds

Returns:

  • (Request)

    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, **options)
  arguments = [subcommand]
  arguments.concat(options[:arguments]) if options[:arguments]

  Request.new(
    command: "npm",
    arguments: arguments,
    directory: directory,
    timeout: options.fetch(:timeout, 300),
    metadata: {
      operation: "npm_#{subcommand}",
      subcommand: subcommand,
    }.merge(options.fetch(:metadata, {})),
  )
end

.rake_task(task_name, directory = Dir.pwd, **options) ⇒ Request

Create a rake task request.

Parameters:

  • task_name (String)

    rake task name

  • directory (String) (defaults to: Dir.pwd)

    project directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :arguments (Array<String>)

    additional task arguments

  • :environment (Hash)

    environment variables

  • :timeout (Integer) — default: 300

    timeout in seconds

Returns:



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, **options)
  arguments = [task_name]
  arguments.concat(options[:arguments]) if options[:arguments]

  Request.new(
    command: "rake",
    arguments: arguments,
    directory: directory,
    environment: options[:environment] || {},
    timeout: options.fetch(:timeout, 300),
    metadata: {
      operation: "rake_task",
      task: task_name,
      arguments: options[:arguments],
    }.merge(options.fetch(:metadata, {})),
  )
end

.ruby_script(script_file, directory = Dir.pwd, **options) ⇒ Request

Create a Ruby script execution request.

Parameters:

  • script_file (String)

    Ruby script file to execute

  • directory (String) (defaults to: Dir.pwd)

    working directory

  • options (Hash)

    additional options

Options Hash (**options):

  • :arguments (Array<String>)

    script arguments

  • :environment (Hash)

    environment variables

  • :timeout (Integer) — default: 120

    timeout in seconds

Returns:

  • (Request)

    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, **options)
  arguments = [script_file]
  arguments.concat(options[:arguments]) if options[:arguments]

  Request.new(
    command: "ruby",
    arguments: arguments,
    directory: directory,
    environment: options[:environment] || {},
    timeout: options.fetch(:timeout, 120),
    metadata: {
      operation: "ruby_script",
      script: script_file,
      arguments: options[:arguments],
    }.merge(options.fetch(:metadata, {})),
  )
end

.system_command(command, arguments = [], **options) ⇒ Request

Create a system command request with validation.

Parameters:

  • command (String)

    system command

  • arguments (Array<String>) (defaults to: [])

    command arguments

  • options (Hash)

    additional options

Options Hash (**options):

  • :directory (String)

    working directory

  • :environment (Hash)

    environment variables

  • :timeout (Integer) — default: 60

    timeout in seconds

Returns:

  • (Request)

    system command request



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 = [], **options)
  Request.new(
    command: command,
    arguments: Array(arguments),
    directory: options[:directory] || Dir.pwd,
    environment: options[:environment] || {},
    timeout: options.fetch(:timeout, 60),
    metadata: {
      operation: "system_command",
      system_command: command,
    }.merge(options.fetch(:metadata, {})),
  )
end