Class: Rodauth::Rails::App

Inherits:
Roda
  • Object
show all
Defined in:
lib/rodauth/rails/app.rb

Overview

The superclass for creating a Rodauth middleware.

Defined Under Namespace

Modules: RequestMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure(*args, **options, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rodauth/rails/app.rb', line 23

def self.configure(*args, **options, &block)
  auth_class = args.shift if args[0].is_a?(Class)
  auth_class ||= Class.new(Rodauth::Rails::Auth)
  name = args.shift if args[0].is_a?(Symbol)

  fail ArgumentError, "need to pass optional Rodauth::Auth subclass and optional configuration name" if args.any?

  # we'll render Rodauth's built-in view templates within Rails layouts
  plugin :render, layout: false unless options[:render] == false

  plugin :rodauth, auth_class: auth_class, name: name, csrf: false, flash: false, json: true, **options, &block

  # we need to do it after request methods from rodauth have been included
  self::RodaRequest.include RequestMethods
end

.controller_pathObject

The newrelic_rpm gem expects this when we pass the roda class as :controller in instrumentation payload.



71
72
73
# File 'lib/rodauth/rails/app.rb', line 71

def self.controller_path
  name.underscore
end

.rodauth!(name) ⇒ Object



65
66
67
# File 'lib/rodauth/rails/app.rb', line 65

def self.rodauth!(name)
  rodauth(name) or fail ArgumentError, "unknown rodauth configuration: #{name.inspect}"
end

Instance Method Details

#flashObject



49
50
51
# File 'lib/rodauth/rails/app.rb', line 49

def flash
  rails_request.flash
end

#rails_cookiesObject



57
58
59
# File 'lib/rodauth/rails/app.rb', line 57

def rails_cookies
  rails_request.cookie_jar
end

#rails_requestObject



61
62
63
# File 'lib/rodauth/rails/app.rb', line 61

def rails_request
  ActionDispatch::Request.new(env)
end

#rails_routesObject



53
54
55
# File 'lib/rodauth/rails/app.rb', line 53

def rails_routes
  ::Rails.application.routes.url_helpers
end