class RSC

Public Class Methods

new(drb_hostname='rse', port: '61000', debug: false) click to toggle source
# File lib/rsc.rb, line 47
def initialize(drb_hostname='rse', port: '61000', debug: false)
  
  @port, @debug = port, debug
  
  drb_start(drb_hostname)
  
end

Public Instance Methods

delete(s=nil) click to toggle source
# File lib/rsc.rb, line 55
def delete(s=nil)
  s ? run_uri(s, :delete) :  @obj.delete
end
get(s=nil) click to toggle source
# File lib/rsc.rb, line 59
def get(s=nil)
  s ? run_uri(s, :get) :  @obj.get
end
post(s=nil, val=nil) click to toggle source
# File lib/rsc.rb, line 63
def post(s=nil, val=nil)
  s ? run_uri(s, :post, value: val) :  @obj.post
end
put(s=nil, val=nil) click to toggle source
# File lib/rsc.rb, line 67
def put(s=nil, val=nil)
  s ? run_uri(s, :put, value: val) :  @obj.put
end
run_job(package, job, params={}, *qargs, package_path: nil) click to toggle source
# File lib/rsc.rb, line 72
def run_job(package, job, params={}, *qargs, package_path: nil)
  @obj.run_job(package, job, params, qargs, package_path)
end

Private Instance Methods

drb_start(host) click to toggle source
# File lib/rsc.rb, line 78
def drb_start(host)
  DRb.start_service
  @obj = DRbObject.new(nil, "druby://#{host}:#{@port}")    
end
method_missing(method_name, *args) click to toggle source
# File lib/rsc.rb, line 83
def method_missing(method_name, *args)

  if @debug then
    puts 'method_missing'.info 
    puts ('method_name: ' + method_name.inspect).debug
  end
  
  begin
    Package.new @obj, method_name.to_s, debug: @debug
  rescue
    # nil will be returned if there is no package by that name
  end
  
end
parse_uri(s) click to toggle source
# File lib/rsc.rb, line 98
def parse_uri(s)
  
  protocol, _, host, package, raw_job, remaining = s.split('/',6)
  
  if remaining then
    
    job = raw_job
    # split on the 1st question mark
    raw_args, raw_params = if remaining =~ /\?/ then
      remaining.split('?',2)
    else
      remaining
    end
    
  elsif raw_job =~ /\?/
    job, raw_params = raw_job.split('?',2)
  else
    job = raw_job
  end
  
  if raw_args or raw_params then
    args = raw_args.split('/') if raw_args
    
    if raw_params then
      params = raw_params.split('&').inject({}) do |r,x| 
        k, v = x.split('=')
        v ? r.merge(k[/\w+$/].to_sym => URI.unescape(v)) : r
      end          
    end

  end    
  
  [host, package, job, args, params]
end
run_uri(s, type=:get, value: nil) click to toggle source
# File lib/rsc.rb, line 133
def run_uri(s, type=:get, value: nil)
  
  host, package, job, args, params = parse_uri(s)
  drb_start host
  @obj.type = type
  
  if value then
    params ||= {}      
    params.merge!(value.is_a?(Hash) ? value : {value: value}) 
  end
  
  @obj.run_job(package, job, params, args)  
  
end