Sha256: 1b46a4fd963c12b4173dcba6118faa4ae246586fa1e14c6c166a51e09efdbf47

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 KB

Contents

module Marty::Diagnostic; class Controller < ActionController::Base
  def self.inherited(klass)
    namespace = klass.name.deconstantize.split('::')[0] rescue ''
    Reporter.namespaces.unshift(namespace)
    super
  end

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

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

  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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
marty-14.3.0 app/controllers/marty/diagnostic/controller.rb
marty-14.0.0 app/controllers/marty/diagnostic/controller.rb
marty-13.0.2 app/controllers/marty/diagnostic/controller.rb
marty-11.0.0 app/controllers/marty/diagnostic/controller.rb
marty-10.0.3 app/controllers/marty/diagnostic/controller.rb
marty-10.0.2 app/controllers/marty/diagnostic/controller.rb
marty-10.0.0 app/controllers/marty/diagnostic/controller.rb
marty-9.5.1 app/controllers/marty/diagnostic/controller.rb
marty-9.5.0 app/controllers/marty/diagnostic/controller.rb
marty-9.3.3 app/controllers/marty/diagnostic/controller.rb
marty-9.3.2 app/controllers/marty/diagnostic/controller.rb