Class: Cuted::Command
- Inherits:
-
Object
- Object
- Cuted::Command
- Includes:
- DRbUndumped
- Defined in:
- lib/cuted/command.rb
Instance Attribute Summary collapse
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#log ⇒ Object
Returns the value of attribute log.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#prowl_key ⇒ Object
Returns the value of attribute prowl_key.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(cmd, opts = {}) ⇒ Command
constructor
A new instance of Command.
-
#run ⇒ Object
Runs in the current thread.
-
#to_s ⇒ Object
Print out dir> command string.
Constructor Details
#initialize(cmd, opts = {}) ⇒ Command
Returns a new instance of Command.
20 21 22 23 24 25 26 27 28 |
# File 'lib/cuted/command.rb', line 20 def initialize(cmd, opts = {}) @cmd = cmd.to_s # If the options are set, use them; otherwise defaults. @dir = opts[:dir] || Dir.pwd # Since we can force opts[:log] to be nil, and we don't want the default. @log = opts.has_key?(:log) ? opts[:log] : 'cute.log' @priority = opts[:priority] || 0 @weight = opts[:weight] || 1 end |
Instance Attribute Details
#cmd ⇒ Object
Returns the value of attribute cmd.
17 18 19 |
# File 'lib/cuted/command.rb', line 17 def cmd @cmd end |
#dir ⇒ Object
Returns the value of attribute dir.
17 18 19 |
# File 'lib/cuted/command.rb', line 17 def dir @dir end |
#log ⇒ Object
Returns the value of attribute log.
17 18 19 |
# File 'lib/cuted/command.rb', line 17 def log @log end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
18 19 20 |
# File 'lib/cuted/command.rb', line 18 def pid @pid end |
#priority ⇒ Object
Returns the value of attribute priority.
17 18 19 |
# File 'lib/cuted/command.rb', line 17 def priority @priority end |
#prowl_key ⇒ Object
Returns the value of attribute prowl_key.
17 18 19 |
# File 'lib/cuted/command.rb', line 17 def prowl_key @prowl_key end |
#weight ⇒ Object
Returns the value of attribute weight.
17 18 19 |
# File 'lib/cuted/command.rb', line 17 def weight @weight end |
Instance Method Details
#run ⇒ Object
Runs in the current thread.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cuted/command.rb', line 31 def run # Make sure the desired working directory exists. FileUtils.makedirs(@dir) if not File.directory?(@dir) # Actually run the command. if @log then @pid = spawn(@cmd, :chdir => @dir, [:out, :err] => [@log, 'a']) else @pid = spawn(@cmd, :chdir => @dir, [:out, :err] => '/dev/null') end # In the forked process, wait for the command to be done. Process.waitall # Report that this command finished. begin require 'prowler' Prowler.verify_certificate = false Prowler.application = 'cuted' Prowler.notify(@cmd, "Finished in #{@dir}", @prowl_key) if @prowl_key rescue LoadError end # Return the CuteCommand. self end |
#to_s ⇒ Object
Print out dir> command string.
58 59 60 |
# File 'lib/cuted/command.rb', line 58 def to_s "#{@dir}> #{@cmd}" end |