File: path_class_methods.rb

package info (click to toggle)
ruby-rodauth 2.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 812 kB
  • sloc: ruby: 7,524; javascript: 100; makefile: 4
file content (22 lines) | stat: -rw-r--r-- 696 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen-string-literal: true

module Rodauth
  Feature.define(:path_class_methods, :PathClassMethods) do
    def post_configure
      super

      klass = self.class
      klass.features.each do |feature_name|
        feature = FEATURES[feature_name]
        feature.routes.each do |handle_meth|
          route = handle_meth.to_s.sub(/\Ahandle_/, '')
          path_meth = :"#{route}_path"
          url_meth = :"#{route}_url"
          instance = klass.allocate.freeze
          klass.define_singleton_method(path_meth){|opts={}| instance.send(path_meth, opts)}
          klass.define_singleton_method(url_meth){|opts={}| instance.send(url_meth, opts)}
        end
      end
    end
  end
end