Module: CommandKit::Env

Included in:
Colors, Command, Commands, Home, Path, Pager, Terminal
Defined in:
lib/command_kit/env.rb,
lib/command_kit/env/home.rb,
lib/command_kit/env/path.rb

Overview

Provides access to environment variables.

Examples

class MyCmd
  include CommandKit::Env

  def main
    home = env['HOME']
    # ...
  end
end

Testing

Can be initialized with a custom env hash for testing purposes.

MyCmd.new(env: {...})

Defined Under Namespace

Modules: Home, Path

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envHash{String => String} (readonly)

The environment variables hash.

Returns:

  • (Hash{String => String})


28
29
30
# File 'lib/command_kit/env.rb', line 28

def env
  @env
end

Instance Method Details

#initialize(env: ENV, **kwargs) ⇒ Object

Initializes #env.

Parameters:

  • env (Hash{String => String}) (defaults to: ENV)

    The given environment for the command. Defaults to the global ENV.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.



41
42
43
44
45
# File 'lib/command_kit/env.rb', line 41

def initialize(env: ENV, **kwargs)
  @env = env

  super(**kwargs)
end