class SystemBrowser::RequestProcessor

Constants

ACTIONS

Public Class Methods

new(request:, session:) click to toggle source
# File lib/system_browser/request_processor.rb, line 8
def initialize(request:, session:)
  @request = request
  @session = session
  @services = [
    Services::GemService,
    Services::BehaviourService,
    Services::MethodService,
    Services::SourceService
  ]
end

Public Instance Methods

process() click to toggle source
# File lib/system_browser/request_processor.rb, line 19
def process
  @request.parse

  if @request.sets_client_pid?
    @session.set_client_pid(@request.client_pid)
  else
    self.process_services
  end
end

Protected Instance Methods

find_service_for(req_service) click to toggle source
# File lib/system_browser/request_processor.rb, line 63
def find_service_for(req_service)
  @services.find { |service| service.service_name == req_service }
end
process_action() click to toggle source
# File lib/system_browser/request_processor.rb, line 51
def process_action
  ACTIONS[@request.action]
end
process_scope(action) click to toggle source
# File lib/system_browser/request_processor.rb, line 55
def process_scope(action)
  case action
  when 'add' then @request.scope
  when 'autoadd' then ''
  else @request.scope
  end
end
process_services() click to toggle source
# File lib/system_browser/request_processor.rb, line 31
def process_services
  service = self.find_service_for(@request.resource).new(
    data: @request.scope,
    other: @request.other)

  data = service.__send__(@request.action)
  data = self.replace_weird_characters(data) if data.instance_of?(String)

  action = self.process_action
  scope = self.process_scope(action)

  data[:behaviour] = @request.scope if scope.empty?

  action_str = "#{action}:#{@request.resource}:#{scope}"
  response = Response.new(action: action_str, data: data)
  response.set_callback_id(@request.callback_id)

  @session.send(response)
end
replace_weird_characters(str) click to toggle source

Temporary hack before we support weird characters for real.

# File lib/system_browser/request_processor.rb, line 69
def replace_weird_characters(str)
  ascii_str = str.force_encoding('ASCII-8BIT')
  ascii_str.encode('UTF-8', undef: :replace, replace: '')
end