Class: Script::Bash
- Inherits:
-
Object
- Object
- Script::Bash
- Defined in:
- lib/plugins/bash.rb
Instance Attribute Summary collapse
-
#injection ⇒ Object
readonly
Returns the value of attribute injection.
Instance Method Summary collapse
- #code(s) ⇒ Object
- #cwd(s) ⇒ Object
- #doit ⇒ Object
- #echo(s) ⇒ Object
- #failure(inj = nil, &block) ⇒ Object
- #group(s) ⇒ Object
-
#initialize(toplevel, injection = nil, &block) ⇒ Bash
constructor
A new instance of Bash.
- #log(s) ⇒ Object
- #success(inj = nil, &block) ⇒ Object
-
#user(s) ⇒ Object
————————————————————— DSL.
Constructor Details
#initialize(toplevel, injection = nil, &block) ⇒ Bash
Returns a new instance of Bash.
9 10 11 12 13 |
# File 'lib/plugins/bash.rb', line 9 def initialize(toplevel, injection = nil, &block) @toplevel = toplevel @injection = injection instance_eval(&block) end |
Instance Attribute Details
#injection ⇒ Object (readonly)
Returns the value of attribute injection.
15 16 17 |
# File 'lib/plugins/bash.rb', line 15 def injection @injection end |
Instance Method Details
#code(s) ⇒ Object
43 |
# File 'lib/plugins/bash.rb', line 43 def code(s); @code = s end |
#cwd(s) ⇒ Object
46 |
# File 'lib/plugins/bash.rb', line 46 def cwd(s); @cwd = s end |
#doit ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/plugins/bash.rb', line 17 def doit if @code command = nil if @user if @user == 'root' command = "sudo /bin/bash" else group = @group || @user command = "sudo -u #{@user} -g #{group} /bin/bash" end else command = "/bin/bash" end if exec_code(command) == 0 @success && @success.doit else @failure && @failure.doit end end end |
#echo(s) ⇒ Object
45 |
# File 'lib/plugins/bash.rb', line 45 def echo(s); @echo = s end |
#failure(inj = nil, &block) ⇒ Object
51 52 53 |
# File 'lib/plugins/bash.rb', line 51 def failure(inj = nil, &block) @failure = Prog.new(@toplevel, inj, &block) end |
#group(s) ⇒ Object
42 |
# File 'lib/plugins/bash.rb', line 42 def group(s); @group = s end |
#log(s) ⇒ Object
44 |
# File 'lib/plugins/bash.rb', line 44 def log(s); @log = s end |
#success(inj = nil, &block) ⇒ Object
48 49 50 |
# File 'lib/plugins/bash.rb', line 48 def success(inj = nil, &block) @success = Prog.new(@toplevel, inj, &block) end |
#user(s) ⇒ Object
DSL
41 |
# File 'lib/plugins/bash.rb', line 41 def user(s); @user = s end |