Class: Reviewer::Command::String::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/command/string/env.rb

Overview

Assembles tool environment variables into a single string or array

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env_pairs) ⇒ self

Creates an instance of env variables for a tool to help generate the command string

Parameters:

  • env_pairs (Hash)
    description


14
15
16
# File 'lib/reviewer/command/string/env.rb', line 14

def initialize(env_pairs)
  @env_pairs = env_pairs
end

Instance Attribute Details

#env_pairsObject (readonly)

Returns the value of attribute env_pairs.



8
9
10
# File 'lib/reviewer/command/string/env.rb', line 8

def env_pairs
  @env_pairs
end

Instance Method Details

#to_aArray<String, nil>

Converts environment variables to an array of KEY=value strings

Returns:

  • (Array<String, nil>)

    array of formatted env vars, nil for empty values



28
29
30
# File 'lib/reviewer/command/string/env.rb', line 28

def to_a
  env_pairs.map { |key, value| env(key, value) }
end

#to_sString

Converts environment variables to a space-separated string

Returns:

  • (String)

    formatted environment variables (e.g., “KEY=value KEY2=value2”)



21
22
23
# File 'lib/reviewer/command/string/env.rb', line 21

def to_s
  to_a.compact.join(' ')
end