Module: CommandKit::Env

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

Overview

Provides access to environment variables.

Examples

class MyCmd
  include CommandKit::Env

  def run
    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, Prefix, Shell

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envHash{String => String} (readonly)

The environment variables hash.

Returns:

  • (Hash{String => String})


30
31
32
# File 'lib/command_kit/env.rb', line 30

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.



43
44
45
46
47
# File 'lib/command_kit/env.rb', line 43

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

  super(**kwargs)
end