Class: RScript

Inherits:
RScriptBase show all
Defined in:
lib/rscript.rb

Instance Method Summary collapse

Constructor Details

#initialize(log: nil, pkg_src: '', cache: 5, debug: false, type: 'job') ⇒ RScript

Returns a new instance of RScript.



53
54
55
56
57
58
59
60
61
62
# File 'lib/rscript.rb', line 53

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



64
65
66
67
# File 'lib/rscript.rb', line 64

def jobs(package)
  a = read_rsfdoc([package])  
  a.map(&:first).uniq
end

#read(raw_args = []) ⇒ Object



69
70
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
# File 'lib/rscript.rb', line 69

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

#resetObject



103
104
105
# File 'lib/rscript.rb', line 103

def reset()
  @rsf_cache.reset
end

#run(raw_args, params = {}, rws = self) ⇒ Object

note: run() was copied from the development file rscript-wrapper.rb



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 108

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.message.to_s + " :: \n" + e.backtrace.join("\n")      
    @log.debug 'rscrcript/error: ' + err_label
    return err_label
  end

end