Class: UffizziCore::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Pundit, AuthManagement, AuthorizationConcern, DependencyInjectionConcern, ResponseService
Defined in:
app/controllers/uffizzi_core/application_controller.rb

Constant Summary collapse

DEFAULT_PAGE =
1
DEFAULT_PER_PAGE =
20
RESCUABLE_EXCEPTIONS =
[RuntimeError, TypeError, NameError, ArgumentError, SyntaxError].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DependencyInjectionConcern

#user_access_module

Methods included from AuthorizationConcern

#init_authorize, #pundit_user

Methods included from AuthManagement

#authenticate_request!, #current_user, #sign_in, #sign_out, #signed_in?

Methods included from ResponseService

#meta

Class Method Details

.responderObject



28
29
30
# File 'app/controllers/uffizzi_core/application_controller.rb', line 28

def self.responder
  UffizziCore::JsonResponder
end

Instance Method Details

#pageObject



50
51
52
# File 'app/controllers/uffizzi_core/application_controller.rb', line 50

def page
  params[:page] || DEFAULT_PAGE
end

#per_pageObject



54
55
56
# File 'app/controllers/uffizzi_core/application_controller.rb', line 54

def per_page
  params[:per_page] || DEFAULT_PER_PAGE
end

#policy_contextObject



24
25
26
# File 'app/controllers/uffizzi_core/application_controller.rb', line 24

def policy_context
  UffizziCore::BaseContext.new(current_user, user_access_module, params)
end

#q_paramObject



46
47
48
# File 'app/controllers/uffizzi_core/application_controller.rb', line 46

def q_param
  params[:q] || ActionController::Parameters.new
end

#render_errors(errors) ⇒ Object



40
41
42
43
44
# File 'app/controllers/uffizzi_core/application_controller.rb', line 40

def render_errors(errors)
  json = { errors: errors }

  render json: json, status: :unprocessable_entity
end

#render_not_foundObject



32
33
34
# File 'app/controllers/uffizzi_core/application_controller.rb', line 32

def render_not_found
  render json: { errors: { title: ['Resource Not Found'] } }, status: :not_found
end

#render_server_error(error) ⇒ Object



36
37
38
# File 'app/controllers/uffizzi_core/application_controller.rb', line 36

def render_server_error(error)
  render json: { errors: { title: [error] } }, status: :internal_server_error
end