Class: RScript
- Inherits:
-
RScriptBase
- Object
- RScriptBase
- RScript
- Defined in:
- lib/rscript.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(log: nil, pkg_src: '', cache: 5, debug: false, type: 'job') ⇒ RScript
constructor
A new instance of RScript.
- #jobs(package) ⇒ Object
- #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.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rscript.rb', line 55 def initialize(log: nil, pkg_src: '', cache: 5, debug: false, type: 'job') puts 'inside RScript' if @debug @log = log @cache = cache @rsf_cache = HashCache.new({cache: cache}) if cache and cache > 0 @jobname = type super(debug: debug) end |
Instance Method Details
#jobs(package) ⇒ Object
66 67 68 69 |
# File 'lib/rscript.rb', line 66 def jobs(package) a = read_rsfdoc([package]) a.map(&:first).uniq end |
#read(raw_args = []) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rscript.rb', line 71 def read(raw_args=[]) puts 'inside read' if @debug 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 = $'; args[i] = nil end end args.compact! puts 'before read_rsfdoc' if @debug a = read_rsfdoc(args) job = a.assoc(ajob.to_sym) out, attr = job.last[:code], job.last[:attributes] raise "job not found" unless out.length > 0 out else out = read_rsfdoc(args).map {|x| x.last[:code]}.join("\n") end @log.info 'RScript/read: code: ' + out.inspect if @log [out, args, attr] end |
#reset ⇒ Object
105 106 107 |
# File 'lib/rscript.rb', line 105 def reset() @rsf_cache.reset end |
#run(raw_args, params = {}, rws = self) ⇒ Object
note: run() was copied from the development file rscript-wrapper.rb
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 147 148 |
# File 'lib/rscript.rb', line 110 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 if @log return err_label end end |