Class: Marty::Diagnostic::Controller

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/marty/diagnostic/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_report(name, diagnostics) ⇒ Object



37
38
39
# File 'app/controllers/marty/diagnostic/controller.rb', line 37

def self.add_report name, diagnostics
  Reporter.reports[name] = diagnostics
end

.inherited(klass) ⇒ Object



2
3
4
5
6
# File 'app/controllers/marty/diagnostic/controller.rb', line 2

def self.inherited(klass)
  namespace = klass.name.deconstantize.split('::')[0] rescue ''
  Reporter.namespaces.unshift(namespace)
  super
end

Instance Method Details

#display_parametersObject



27
28
29
30
31
32
33
34
35
# File 'app/controllers/marty/diagnostic/controller.rb', line 27

def display_parameters
  local  = params[:scope] == 'local'
  data   = local ? @result : @result['data']
  errors = local ? Reporter.errors(data) : @result['errors']
  {
    'display' => Reporter.displays(data),
    'errors' => errors
  }
end

#opObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/marty/diagnostic/controller.rb', line 8

def op
  begin
    @result = Reporter.run(request)
  rescue NameError
    render file: 'public/400', formats: [:html], status: 400, layout: false
  else
    respond_to do |format|
      format.html {@result = display_parameters}
      format.json {render json: process_result_for_api}
    end
  end
end

#process_result_for_apiObject



21
22
23
24
25
# File 'app/controllers/marty/diagnostic/controller.rb', line 21

def process_result_for_api
  @result.delete('data') unless request.params['data'] == 'true'
  @result.delete('errors') if @result['errors'] && @result['errors'].empty?
  @result
end