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.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rscript.rb', line 107 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
118 119 120 121 |
# File 'lib/rscript.rb', line 118 def jobs(package) a = read_rsfdoc([package]) a.map(&:first).uniq end |
#read(raw_args = []) ⇒ Object
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 149 150 151 152 153 154 155 |
# File 'lib/rscript.rb', line 123 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
157 158 159 |
# File 'lib/rscript.rb', line 157 def reset() @rsf_cache.reset end |
#run(raw_args, params = {}, rws = self) ⇒ Object
note: run() was copied from the development file rscript-wrapper.rb
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rscript.rb', line 162 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 |