Method: CommandMapper::Command#initialize

Defined in:
lib/command_mapper/command.rb

#initialize(params = {}, command_name: self.class.command_name, command_path: nil, command_env: {}, **kwargs) {|self| ... } ⇒ Command

Initializes the command.

Examples:

with a symbol Hash

MyCommand.new({foo: 'bar', baz: 'qux'})

with a keyword arguments

MyCommand.new(foo: 'bar', baz: 'qux')

with a custom env Hash:

MyCommand.new({foo: 'bar', baz: 'qux'}, env: {'FOO' =>'bar'})
MyCommand.new(foo: 'bar', baz: 'qux', env: {'FOO' => 'bar'})

Parameters:

  • params (Hash{Symbol => Object}) (defaults to: {})

    The option and argument values.

  • command_name (String) (defaults to: self.class.command_name)

    Overrides the command with a custom command name.

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

    Overrides the command with a custom path to the command.

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

    Custom environment variables to pass to the command.

  • kwargs (Hash{Symbol => Object})

    Additional keywords arguments. These will be used to populate the command's params.

Yields:

  • (self)

    The newly initialized command.

Yield Parameters:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/command_mapper/command.rb', line 71

def initialize(params={}, command_name: self.class.command_name,
                          command_path: nil,
                          command_env:  {},
                          **kwargs)
  @command_name = command_name
  @command_path = command_path
  @command_env  = command_env

  params = params.merge(kwargs)

  params.each do |name,value|
    self[name] = value
  end

  yield self if block_given?
end