Class: RScript
- Inherits:
-
RScriptBase
- Object
- RScriptBase
- RScript
- Defined in:
- lib/rscript.rb
Instance Method Summary collapse
-
#initialize(log: nil, pkg_src: '', cache: 5) ⇒ RScript
constructor
A new instance of RScript.
- #read(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) ⇒ RScript
Returns a new instance of RScript.
47 48 49 50 51 52 53 |
# File 'lib/rscript.rb', line 47 def initialize(log: nil, pkg_src: '', cache: 5) @log = log @cache = cache @rsf_cache = HashCache.new({cache: cache}) if cache > 0 end |
Instance Method Details
#read(args = []) ⇒ Object
55 56 57 58 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 |
# File 'lib/rscript.rb', line 55 def read(args=[]) @log.info 'RScript/read: args: ' + args.inspect if @log threads = [] if args.to_s[/\/\/job:/] then ajob = [] args.each_index do |i| if args[i].to_s[/\/\/job:/] then ajob << "@id='#{$'}'"; args[i] = nil end end args.compact! out = read_rsf(args) do |doc| doc.root.xpath("//job[#{ajob.join(' or ')}]").map do |job| job.xpath('script').map {|s| read_script(s)}.join("\n") end.join("\n") 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] end |
#reset ⇒ Object
91 92 93 |
# File 'lib/rscript.rb', line 91 def reset() @rsf_cache.reset end |
#run(raw_args, params = {}, rws = self) ⇒ Object
note: run() was copied from the development file rscript-wrapper.rb
96 97 98 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 138 139 140 141 142 143 144 145 146 |
# File 'lib/rscript.rb', line 96 def run(raw_args, params={}, rws=self) @log.info 'RScript/run: raw_args: ' + raw_args.inspect if @log if 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[: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 = self.read raw_args @log.info 'RScript/run: code2: ' + code2 if @log begin =begin thread = Thread.new(code2) do |x| begin Thread.current['result'] = eval x rescue @logger.debug('RScript -> eval: ' + ($!).inspect) if @logger end end thread.join =end #puts 'code2 :' + code2.inspect r = eval code2 #r = thread['result'] params = {} return r rescue Exception => e params = {} err_label = e..to_s + " :: \n" + e.backtrace.join("\n") return err_label end end |