Class: RScript
- Inherits:
-
RScriptBase
- Object
- RScriptBase
- RScript
- Defined in:
- lib/rscript.rb
Instance Method Summary collapse
-
#initialize(log: nil, pkg_src: '', cache: 5, debug: false, type: 'job') ⇒ RScript
constructor
A new instance of RScript.
- #read(raw_args = []) ⇒ Object
- #reset ⇒ Object
-
#run(raw_args, params = {}, rws = self) ⇒ Object
note: run() was copied from the development file rscript-wrapper.rb.
Constructor Details
#initialize(log: nil, pkg_src: '', cache: 5, debug: false, type: 'job') ⇒ RScript
Returns a new instance of RScript.
49 50 51 52 53 54 55 56 57 |
# File 'lib/rscript.rb', line 49 def initialize(log: nil, pkg_src: '', cache: 5, debug: false, type: 'job') @log = log @cache = cache @rsf_cache = HashCache.new({cache: cache}) if cache > 0 @debug = debug @jobname = type end |
Instance Method Details
#read(raw_args = []) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rscript.rb', line 59 def read(raw_args=[]) args = raw_args.clone @log.info 'RScript/read: args: ' + args.inspect if @log threads = [] if args.to_s[/\/\/#{@jobname}:/] then ajob = '' args.each_index do |i| if args[i].to_s[/\/\/#{@jobname}:/] then ajob = "@id='#{$'}'"; args[i] = nil puts 'ajob: ' + ajob.inspect end end args.compact! out, attr = read_rsf(args) do |doc| job = doc.root.element("//#{@jobname}[#{ajob}]") [job.xpath('script').map {|s| read_script(s)}.join("\n"), job.attributes] end raise "job not found" unless out.length > 0 out else out = read_rsf(args) {|doc| doc.root.xpath('//script').map {|s| read_script(s)}}.join("\n") end @log.info 'RScript/read: code: ' + out.inspect if @log [out, args, attr] end |
#reset ⇒ Object
94 95 96 |
# File 'lib/rscript.rb', line 94 def reset() @rsf_cache.reset end |
#run(raw_args, params = {}, rws = self) ⇒ Object
note: run() was copied from the development file rscript-wrapper.rb
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rscript.rb', line 99 def run(raw_args, params={}, rws=self) @log.info 'RScript/run: raw_args: ' + raw_args.inspect if @log puts 'raw_args: ' + raw_args.inspect if @debug if params and params[:splat] then params.each do |k,v| params.delete k unless k == :splat or k == :package or k == :job or k == :captures end end if params and params[:splat] and params[:splat].length > 0 then h = params[:splat].first[1..-1].split('&').inject({}) do |r,x| k, v = x.split('=') v ? r.merge(k[/\w+$/].to_sym => v) : r end params.merge! h end code2, args, attr = self.read raw_args.clone puts 'code2 : ' + code2.inspect if @debug @log.info 'RScript/run: code2: ' + code2 if @log begin r = eval code2 params = {} return r rescue Exception => e params = {} err_label = e..to_s + " :: \n" + e.backtrace.join("\n") @log.debug 'rscrcript/error: ' + err_label return err_label end end |