Class: CommandDesigner::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/command-designer/command.rb

Overview

A concpet of command that can be extended multiple times

Examples:


command = CommandDesigner::Command.new("test")
command.change {|command| "env #{command}" }
command.command # => "env test"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Command

initialize command and initial_command

Parameters:

  • args (Array<String>)

    The command name to build upon



28
29
30
31
# File 'lib/command-designer/command.rb', line 28

def initialize(*args)
  @initial_command = args || []
  reset
end

Instance Attribute Details

#commandString (readonly)

Returns current value of the command.

Returns:

  • (String)

    current value of the command



21
22
23
# File 'lib/command-designer/command.rb', line 21

def command
  @command
end

#initial_commandArray (readonly)

Returns initial value of the command and parameters.

Returns:

  • (Array)

    initial value of the command and parameters



24
25
26
# File 'lib/command-designer/command.rb', line 24

def initial_command
  @initial_command
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if other object equals command_name, false otherwise.

Returns:

  • (Boolean)

    true if other object equals command_name, false otherwise



52
53
54
# File 'lib/command-designer/command.rb', line 52

def ==(other)
  self.command_name == other
end

#change {|command| ... } ⇒ String

Yields a block to change the command

Yields:

  • (command)

    a block to change the command

Yield Parameters:

  • command (String)

    the current command

Returns:

  • (String)

    the new command



42
43
44
# File 'lib/command-designer/command.rb', line 42

def change(&block)
  @command = yield @command
end

#command_nameString

Returns just the first part of the command: command_name.

Returns:

  • (String)

    just the first part of the command: command_name



47
48
49
# File 'lib/command-designer/command.rb', line 47

def command_name
  @initial_command.first
end

#resetObject

reset command to it’s initial state



34
35
36
# File 'lib/command-designer/command.rb', line 34

def reset
  @command = Shellwords.join(@initial_command)
end