Class: DeploYML::Shell

Inherits:
Object
  • Object
show all
Includes:
Shellwords, Thor::Shell
Defined in:
lib/deployml/shell.rb

Overview

Provides common methods used by both LocalShell and RemoteShell.

Direct Known Subclasses

LocalShell, RemoteShell

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) {|session| ... } ⇒ Shell

Initializes a shell session.

Parameters:

  • uri (Addressable::URI, String)

    The URI of the shell.

Yields:

  • (session)

    If a block is given, it will be passed the new shell session.

Yield Parameters:

  • session (ShellSession)

    The shell session.



28
29
30
31
32
33
34
35
36
# File 'lib/deployml/shell.rb', line 28

def initialize(uri)
  @uri = uri

  if block_given?
    status "Entered #{@uri}."
    yield self
    status "Leaving #{@uri} ..."
  end
end

Instance Attribute Details

#uriObject (readonly)

The URI of the Shell.



14
15
16
# File 'lib/deployml/shell.rb', line 14

def uri
  @uri
end

Instance Method Details

#echo(message) ⇒ Object

Place holder method.

Since:

  • 0.5.0



65
66
# File 'lib/deployml/shell.rb', line 65

def echo(message)
end

#exec(command) ⇒ Object

Runs a command in the shell.

Parameters:

  • command (String)

    The command to run.

See Also:

Since:

  • 0.5.0



56
57
58
# File 'lib/deployml/shell.rb', line 56

def exec(command)
  run(*shellwords(command))
end

#rake(task, *arguments) ⇒ Object

Executes a Rake task.

Parameters:

  • task (Symbol, String)

    Name of the Rake task to run.

  • arguments (Array<String>)

    Additional arguments for the Rake task.



77
78
79
# File 'lib/deployml/shell.rb', line 77

def rake(task,*arguments)
  run 'rake', rake_task(task,*arguments)
end

#rake_task(name, *arguments) ⇒ Object (protected)

Builds a rake task name.

Parameters:

  • name (String, Symbol)

    The name of the rake task.

  • arguments (Array)

    Additional arguments to pass to the rake task.

  • The (String)

    rake task name to be called.



107
108
109
110
111
112
113
114
115
# File 'lib/deployml/shell.rb', line 107

def rake_task(name,*arguments)
  name = name.to_s

  unless arguments.empty?
    name += ('[' + arguments.join(',') + ']')
  end

  return name
end

#run(program, *arguments) ⇒ Object

Place holder method.

Since:

  • 0.5.0



43
44
# File 'lib/deployml/shell.rb', line 43

def run(program,*arguments)
end

#status(message) ⇒ Object

Prints a status message.

Parameters:

  • message (String)

    The message to print.

Since:

  • 0.4.0



89
90
91
# File 'lib/deployml/shell.rb', line 89

def status(message)
  echo "#{Color::GREEN}>>> #{message}#{Color::CLEAR}"
end