class Ratch::Script
The Ratch
Script
class is used to run stand-alone Ratch
scripts. Yep, this is actaully a class named exactly for what it is. How rare.
Public Class Methods
execute(script, *args)
click to toggle source
# File lib/ratch/script.rb, line 27 def self.execute(script, *args) script = new(script, *args) script.execute! end
new(file, *args)
click to toggle source
Calls superclass method
Ratch::CLI::new
# File lib/ratch/script.rb, line 33 def initialize(file, *args) @_file = file.to_s #extend self super(*args) #@_stdout = options[:stdout] || $stdout #@_stderr = options[:stderr] || $stderr #@_stdin = options[:stdin] || $stdin end
Public Instance Methods
define_method(name, &block)
click to toggle source
Pass-thru to singleton class.
# File lib/ratch/script.rb, line 94 def define_method(name, &block) (class << self; self; end).__send__(:define_method, &block) end
execute!()
click to toggle source
Be cautious about calling this in a script –an infinite loop could easily ensue.
# File lib/ratch/script.rb, line 52 def execute! old = $0 begin $0 = script_file instance_eval(File.read(script_file), script_file, 1) ensure $0 = old end end
Also aliased as: run!
report(message)
click to toggle source
script_file()
click to toggle source
Returns the file name of the script.
# File lib/ratch/script.rb, line 46 def script_file @_file end
status(message)
click to toggle source
# File lib/ratch/script.rb, line 81 def status(message) #@_stdout.puts message unless quiet? puts message unless quiet? # dryrun? or trace? end
trace(message)
click to toggle source
Internal status report. Only output if in trace mode.
# File lib/ratch/script.rb, line 88 def trace(message) #@_stdout.puts message if trace? puts message if trace? end