Method: OpenC3::ServerProxy#method_missing

Defined in:
lib/openc3/script/script.rb

#method_missing(method_name, *method_params, **kw_params) ⇒ Object

Ruby method which captures any method calls on this object. This allows us to proxy the methods to the API server through the JsonDRbObject.



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/openc3/script/script.rb', line 246

def method_missing(method_name, *method_params, **kw_params)
  # Must call shutdown and disconnect on the JsonDRbObject itself
  # to avoid it being sent to the API
  kw_params[:scope] = $openc3_scope unless kw_params[:scope]
  case method_name
  when :shutdown
    @json_drb.shutdown
  when :request
    @json_drb.request(*method_params, **kw_params)
  else
    if $disconnect
      result = nil
      # If :disconnect is there delete it and return the value
      # If it is not there, delete returns nil
      disconnect = kw_params.delete(:disconnect)
      # The only commands allowed through in disconnect mode are read-only
      # Thus we allow the get, list, tlm and limits_enabled and subscribe methods
      if method_name =~ /get_\w*|list_\w*|^tlm|limits_enabled|subscribe/
        result = @json_drb.method_missing(method_name, *method_params, **kw_params)
      end
      # If they overrode the return value using the disconnect keyword then return that
      return disconnect ? disconnect : result
    else
      @json_drb.method_missing(method_name, *method_params, **kw_params)
    end
  end
end