Module: Inprovise::CmdHelper
- Defined in:
- lib/inprovise/cmd_helper.rb
Overview
Command helper for Inprovise
- Author
-
Martin Corino
- License
-
Distributes under the same license as Ruby
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
Class Method Summary collapse
- .default_implementation ⇒ Object
- .default_implementation=(impl) ⇒ Object
- .define(impl, base = ::Object, &definition) ⇒ Object
- .get(node, impl) ⇒ Object
- .implementations ⇒ Object
Instance Method Summary collapse
-
#admin_user ⇒ Object
platform properties.
- #binary_exists?(bin) ⇒ Boolean
- #cat(path) ⇒ Object
- #copy(from, to) ⇒ Object
- #cwd ⇒ Object
- #delete(path) ⇒ Object
- #directory?(path) ⇒ Boolean
- #download(from, to) ⇒ Object
-
#echo(arg) ⇒ Object
basic commands.
- #env(var) ⇒ Object
- #env_reference(varname) ⇒ Object
- #exists?(path) ⇒ Boolean
- #file?(path) ⇒ Boolean
- #hash_for(path) ⇒ Object
-
#initialize(channel) ⇒ Object
default init.
- #mkdir(path) ⇒ Object
- #owner(path) ⇒ Object
- #permissions(path) ⇒ Object
-
#run(cmd, forcelog = false) ⇒ Object
generic command execution.
-
#set_cwd(path) ⇒ Object
must return previous value.
- #set_owner(path, user, group = nil) ⇒ Object
- #set_permissions(path, perm) ⇒ Object
-
#sudo ⇒ Object
return sudo helper.
-
#upload(from, to) ⇒ Object
file management.
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
37 38 39 |
# File 'lib/inprovise/cmd_helper.rb', line 37 def channel @channel end |
Class Method Details
.default_implementation ⇒ Object
14 15 16 |
# File 'lib/inprovise/cmd_helper.rb', line 14 def default_implementation @default ||= 'linux' end |
.default_implementation=(impl) ⇒ Object
18 19 20 |
# File 'lib/inprovise/cmd_helper.rb', line 18 def default_implementation=(impl) @default = impl end |
.define(impl, base = ::Object, &definition) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/inprovise/cmd_helper.rb', line 22 def define(impl, base=::Object, &definition) implklass = Class.new(base) do include Inprovise::CmdHelper end implklass.class_eval(&definition) implementations[impl.to_s] = implklass implklass end |
.get(node, impl) ⇒ Object
31 32 33 |
# File 'lib/inprovise/cmd_helper.rb', line 31 def get(node, impl) implementations[impl || default_implementation].new(node.channel) end |
.implementations ⇒ Object
10 11 12 |
# File 'lib/inprovise/cmd_helper.rb', line 10 def implementations @implementations ||= {} end |
Instance Method Details
#admin_user ⇒ Object
platform properties
46 47 48 |
# File 'lib/inprovise/cmd_helper.rb', line 46 def admin_user nil end |
#binary_exists?(bin) ⇒ Boolean
142 143 144 |
# File 'lib/inprovise/cmd_helper.rb', line 142 def binary_exists?(bin) false end |
#cat(path) ⇒ Object
94 95 96 |
# File 'lib/inprovise/cmd_helper.rb', line 94 def cat(path) nil end |
#copy(from, to) ⇒ Object
118 119 120 |
# File 'lib/inprovise/cmd_helper.rb', line 118 def copy(from, to) nil end |
#cwd ⇒ Object
54 55 56 |
# File 'lib/inprovise/cmd_helper.rb', line 54 def cwd nil end |
#delete(path) ⇒ Object
122 123 124 |
# File 'lib/inprovise/cmd_helper.rb', line 122 def delete(path) nil end |
#directory?(path) ⇒ Boolean
114 115 116 |
# File 'lib/inprovise/cmd_helper.rb', line 114 def directory?(path) false end |
#download(from, to) ⇒ Object
80 81 82 |
# File 'lib/inprovise/cmd_helper.rb', line 80 def download(from, to) @channel.download(from, to) end |
#echo(arg) ⇒ Object
basic commands
86 87 88 |
# File 'lib/inprovise/cmd_helper.rb', line 86 def echo(arg) nil end |
#env(var) ⇒ Object
90 91 92 |
# File 'lib/inprovise/cmd_helper.rb', line 90 def env(var) echo(env_reference(var)) end |
#env_reference(varname) ⇒ Object
50 51 52 |
# File 'lib/inprovise/cmd_helper.rb', line 50 def env_reference(varname) nil end |
#exists?(path) ⇒ Boolean
106 107 108 |
# File 'lib/inprovise/cmd_helper.rb', line 106 def exists?(path) false end |
#file?(path) ⇒ Boolean
110 111 112 |
# File 'lib/inprovise/cmd_helper.rb', line 110 def file?(path) false end |
#hash_for(path) ⇒ Object
98 99 100 |
# File 'lib/inprovise/cmd_helper.rb', line 98 def hash_for(path) nil end |
#initialize(channel) ⇒ Object
default init
40 41 42 |
# File 'lib/inprovise/cmd_helper.rb', line 40 def initialize(channel) @channel = channel end |
#mkdir(path) ⇒ Object
102 103 104 |
# File 'lib/inprovise/cmd_helper.rb', line 102 def mkdir(path) nil end |
#owner(path) ⇒ Object
134 135 136 |
# File 'lib/inprovise/cmd_helper.rb', line 134 def owner(path) nil end |
#permissions(path) ⇒ Object
126 127 128 |
# File 'lib/inprovise/cmd_helper.rb', line 126 def (path) 0 end |
#run(cmd, forcelog = false) ⇒ Object
generic command execution
65 66 67 |
# File 'lib/inprovise/cmd_helper.rb', line 65 def run(cmd, forcelog=false) @channel.run(cmd,forcelog) end |
#set_cwd(path) ⇒ Object
must return previous value
59 60 61 |
# File 'lib/inprovise/cmd_helper.rb', line 59 def set_cwd(path) nil end |
#set_owner(path, user, group = nil) ⇒ Object
138 139 140 |
# File 'lib/inprovise/cmd_helper.rb', line 138 def set_owner(path, user, group=nil) nil end |
#set_permissions(path, perm) ⇒ Object
130 131 132 |
# File 'lib/inprovise/cmd_helper.rb', line 130 def (path, perm) nil end |
#sudo ⇒ Object
return sudo helper
70 71 72 |
# File 'lib/inprovise/cmd_helper.rb', line 70 def sudo nil end |
#upload(from, to) ⇒ Object
file management
76 77 78 |
# File 'lib/inprovise/cmd_helper.rb', line 76 def upload(from, to) @channel.upload(from, to) end |