Class: DeploYML::Shell
- Inherits:
-
Object
- Object
- DeploYML::Shell
- Includes:
- Shellwords, Thor::Shell
- Defined in:
- lib/deployml/shell.rb
Overview
Provides common methods used by both LocalShell and RemoteShell.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
The URI of the Shell.
Instance Method Summary collapse
-
#echo(message) ⇒ Object
Place holder method.
-
#exec(command) ⇒ Object
Place holder method.
-
#initialize(uri, environment = nil) {|session| ... } ⇒ Shell
constructor
Initializes a shell session.
-
#rake(task, *arguments) ⇒ Object
Executes a Rake task.
-
#rake_task(name, *arguments) ⇒ String
protected
Builds a
rake
task name. -
#ruby(program, *arguments) ⇒ Object
Executes a Ruby program.
-
#run(program, *arguments) ⇒ Object
Place holder method.
-
#shellescape(str) ⇒ String
protected
Escapes a string so that it can be safely used in a Bourne shell command line.
-
#status(message) ⇒ Object
Prints a status message.
Constructor Details
#initialize(uri, environment = nil) {|session| ... } ⇒ Shell
Initializes a shell session.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/deployml/shell.rb', line 31 def initialize(uri,environment=nil) @uri = uri @environment = environment if block_given? status "Entered #{@uri}." yield self status "Leaving #{@uri} ..." end end |
Instance Attribute Details
#uri ⇒ Object (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.
66 67 |
# File 'lib/deployml/shell.rb', line 66 def echo() end |
#exec(command) ⇒ Object
Place holder method.
58 59 |
# File 'lib/deployml/shell.rb', line 58 def exec(command) end |
#rake(task, *arguments) ⇒ Object
Executes a Rake task.
103 104 105 |
# File 'lib/deployml/shell.rb', line 103 def rake(task,*arguments) ruby('rake', rake_task(task,*arguments)) end |
#rake_task(name, *arguments) ⇒ String (protected)
Builds a rake
task name.
170 171 172 173 174 175 176 177 178 |
# File 'lib/deployml/shell.rb', line 170 def rake_task(name,*arguments) name = name.to_s unless arguments.empty? name += ('[' + arguments.join(',') + ']') end return name end |
#ruby(program, *arguments) ⇒ Object
Executes a Ruby program.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/deployml/shell.rb', line 80 def ruby(program,*arguments) command = [program, *arguments] # assume that `.rb` scripts do not have a `#!/usr/bin/env ruby` command.unshift('ruby') if program[-3,3] == '.rb' # if the environment uses bundler, run all ruby commands via `bundle exec` if (@environment && @environment.bundler) command.unshift('bundle','exec') end run(*command) end |
#run(program, *arguments) ⇒ Object
Place holder method.
47 48 |
# File 'lib/deployml/shell.rb', line 47 def run(program,*arguments) end |
#shellescape(str) ⇒ String (protected)
Vendored from shellwords.rb
line 72 from Ruby 1.9.2.
Escapes a string so that it can be safely used in a Bourne shell command line.
Note that a resulted string should be used unquoted and is not intended for use in double quotes nor in single quotes.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/deployml/shell.rb', line 141 def shellescape(str) # An empty argument will be skipped, so return empty quotes. return "''" if str.empty? str = str.dup # Process as a single byte sequence because not all shell # implementations are multibyte aware. str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1") # A LF cannot be escaped with a backslash because a backslash + LF # combo is regarded as line continuation and simply ignored. str.gsub!(/\n/, "'\n'") return str end |
#status(message) ⇒ Object
Prints a status message.
115 116 117 |
# File 'lib/deployml/shell.rb', line 115 def status() echo "#{Color::GREEN}>>> #{}#{Color::CLEAR}" end |