Module: Plutonium::Auth::Rodauth

Defined in:
lib/plutonium/auth/rodauth.rb

Class Method Summary collapse

Class Method Details

.for(name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/plutonium/auth/rodauth.rb', line 4

def self.for(name)
  mod = Module.new
  mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
    extend ActiveSupport::Concern

    included do
      helper_method :current_user
      helper_method :logout_url
      helper_method :profile_url
    end

    private

    def rodauth(name = :#{name})
      instance = super(name)
      instance.url_options = default_url_options.presence
      instance
    end

    def current_user
      rodauth.rails_account
    end

    def logout_url
      rodauth.logout_path
    end

    # Override this method to return your profile page URL.
    # When defined, a "Profile" link will appear in the user menu.
    # Example: rodauth.change_password_path or your custom profile_path
    def profile_url
      nil
    end

    define_singleton_method(:to_s) { "Plutonium::Auth::Rodauth(:#{name})" }
    define_singleton_method(:inspect) { "Plutonium::Auth::Rodauth(:#{name})" }
  RUBY
  mod
end