Module: Rails::RFC6570::Extensions::NamedRouteCollection

Defined in:
lib/rails/rfc6570.rb

Instance Method Summary collapse

Instance Method Details

#add(name, route) ⇒ Object Also known as: []=



83
84
85
86
# File 'lib/rails/rfc6570.rb', line 83

def add(name, route)
  super
  define_rfc6570_helpers name, route, @url_helpers_module, @url_helpers
end

#define_rfc6570_helpers(name, route, mod, set) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rails/rfc6570.rb', line 45

def define_rfc6570_helpers(name, route, mod, set)
  rfc6570_name      = :"#{name}_rfc6570"
  rfc6570_url_name  = :"#{name}_url_rfc6570"
  rfc6570_path_name = :"#{name}_path_rfc6570"

  [rfc6570_name, rfc6570_url_name, rfc6570_path_name].each do |helper|
    mod.send :undef_method, helper if mod.respond_to? helper
  end

  mod.module_eval do
    define_method(rfc6570_name) do |**opts|
      ::Rails::RFC6570.build_url_template(self, route, **opts)
    end

    define_method(rfc6570_url_name) do |**opts|
      ::Rails::RFC6570.build_url_template(
        self,
        route,
        **opts,
        path_only: false,
      )
    end

    define_method(rfc6570_path_name) do |**opts|
      ::Rails::RFC6570.build_url_template(
        self,
        route,
        **opts,
        path_only: true,
      )
    end
  end

  set << rfc6570_name
  set << rfc6570_url_name
  set << rfc6570_path_name
end

#to_rfc6570(opts = {}) ⇒ Object



41
42
43
# File 'lib/rails/rfc6570.rb', line 41

def to_rfc6570(opts = {})
  routes.to_h {|n, r| [n, r.to_rfc6570(opts)] }
end