Class: Rodauth::Rails::Tasks::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/rodauth/rails/tasks/routes.rb

Constant Summary collapse

IGNORE =
[:webauthn_setup_js, :webauthn_auth_js, :webauthn_autofill_js]
JSON_POST =
[:two_factor_manage, :two_factor_auth]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_class) ⇒ Routes

Returns a new instance of Routes.



10
11
12
# File 'lib/rodauth/rails/tasks/routes.rb', line 10

def initialize(auth_class)
  @auth_class = auth_class
end

Instance Attribute Details

#auth_classObject (readonly)

Returns the value of attribute auth_class.



8
9
10
# File 'lib/rodauth/rails/tasks/routes.rb', line 8

def auth_class
  @auth_class
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rodauth/rails/tasks/routes.rb', line 14

def call
  routes = auth_class.route_hash.map do |path, handle_method|
    route_name = handle_method.to_s.delete_prefix("handle_").to_sym
    next if IGNORE.include?(route_name)
    verbs = route_verbs(route_name)

    [
      verbs.join("|"),
      "#{rodauth.prefix}#{path}",
      "rodauth#{configuration_name && "(:#{configuration_name})"}.#{route_name}_path",
    ]
  end

  routes.compact!
  padding = routes.transpose.map { |string| string.map(&:length).max }

  output_lines = routes.map do |columns|
    [columns[0].ljust(padding[0]), columns[1].ljust(padding[1]), columns[2]].join("  ")
  end

  puts "\n  #{output_lines.join("\n  ")}"
end