Method: Makit::Commands::Request.from_hash

Defined in:
lib/makit/commands/request.rb

.from_hash(command_hash) ⇒ Request

Create a request from hash representation.

Examples:

Request.from_hash({
  "command" => "git",
  "arguments" => ["clone", "https://github.com/user/repo.git"],
  "timeout" => 300
})

Parameters:

  • command_hash (Hash)

    hash containing command information

Returns:

Raises:

  • (ArgumentError)

    if hash is invalid



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/makit/commands/request.rb', line 135

def self.from_hash(command_hash)
  raise ArgumentError, "Command hash cannot be nil" if command_hash.nil?

  # Convert string keys to symbols for consistency

  hash = command_hash.is_a?(Hash) ? normalize_hash_keys(command_hash) : command_hash

  new(
    command: hash[:command] || hash["command"],
    arguments: hash[:arguments] || hash["arguments"] || [],
    environment: hash[:environment] || hash["environment"] || {},
    directory: hash[:directory] || hash["directory"],
    timeout: hash[:timeout] || hash["timeout"],
    metadata: hash[:metadata] || hash["metadata"] || {},
    exit_on_failure: hash[:exit_on_failure] || hash["exit_on_failure"],
    show_stderr: hash[:show_stderr] || hash["show_stderr"],
    show_stdout: hash[:show_stdout] || hash["show_stdout"],
  )
end