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
- #move(_from, _to) ⇒ 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
146 147 148 |
# File 'lib/inprovise/cmd_helper.rb', line 146 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
126 127 128 |
# File 'lib/inprovise/cmd_helper.rb', line 126 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 |
#move(_from, _to) ⇒ Object
122 123 124 |
# File 'lib/inprovise/cmd_helper.rb', line 122 def move(_from, _to) nil end |
#owner(_path) ⇒ Object
138 139 140 |
# File 'lib/inprovise/cmd_helper.rb', line 138 def owner(_path) nil end |
#permissions(_path) ⇒ Object
130 131 132 |
# File 'lib/inprovise/cmd_helper.rb', line 130 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
142 143 144 |
# File 'lib/inprovise/cmd_helper.rb', line 142 def set_owner(_path, _user, _group=nil) nil end |
#set_permissions(_path, _perm) ⇒ Object
134 135 136 |
# File 'lib/inprovise/cmd_helper.rb', line 134 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 |