Class: RSC
- Inherits:
-
Object
show all
- Defined in:
- lib/rsc.rb
Defined Under Namespace
Classes: Package
Instance Method Summary
collapse
Constructor Details
#initialize(drb_hostname = 'rse', port: '61000', odrb2: false, debug: false) ⇒ RSC
Returns a new instance of RSC.
47
48
49
50
51
52
53
54
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
|
# File 'lib/rsc.rb', line 47
def initialize(drb_hostname='rse', port: '61000', odrb2: false, debug: false)
@debug = debug
DRb.start_service
if odrb2 or port == '57844' then
@port = port =~ /^610[0-9]{2}/ ? '57844' : port
@obj = DRbObject.new(nil, "druby://#{drb_hostname}:#{@port}")
parent = @obj
@obj&.services.each do |name, methods|
class_name = name.capitalize
klass = Object.const_set(class_name,Class.new)
klass.class_eval do
methods.each do |method_name|
define_method method_name do |*args|
parent.call name, method_name, *args
end
end
end
define_singleton_method name do
klass.new
end
end
@odrb2 = true
else
@port = port
@obj = DRbObject.new(nil, "druby://#{drb_hostname}:#{@port}")
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/rsc.rb', line 121
def method_missing(method_name, *args)
if @debug then
puts 'method_missing'.info
puts ('method_name: ' + method_name.inspect).debug
end
if not @odrb2 then
begin
Package.new @obj, method_name.to_s, debug: @debug
rescue
end
end
end
|
Instance Method Details
#delete(s = nil) ⇒ Object
jr: 2022-04-23 the following public methods should be conditionally
created since they are specific to classic RSC and not odrb2
93
94
95
|
# File 'lib/rsc.rb', line 93
def delete(s=nil)
s ? run_uri(s, :delete) : @obj.delete
end
|
#get(s = nil) ⇒ Object
97
98
99
|
# File 'lib/rsc.rb', line 97
def get(s=nil)
s ? run_uri(s, :get) : @obj.get
end
|
#post(s = nil, val = nil) ⇒ Object
101
102
103
|
# File 'lib/rsc.rb', line 101
def post(s=nil, val=nil)
s ? run_uri(s, :post, value: val) : @obj.post
end
|
#put(s = nil, val = nil) ⇒ Object
105
106
107
|
# File 'lib/rsc.rb', line 105
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) ⇒ Object
110
111
112
|
# File 'lib/rsc.rb', line 110
def run_job(package, job, params={}, *qargs, package_path: nil)
@obj.run_job(package, job, params, qargs, package_path)
end
|