module Rails::RFC6570::Extensions::NamedRouteCollection

Public Instance Methods

[]=(name, route)
Alias for: add
add(name, route) click to toggle source
Calls superclass method
# File lib/rails/rfc6570.rb, line 83
def add(name, route)
  super
  define_rfc6570_helpers name, route, @url_helpers_module, @url_helpers
end
Also aliased as: []=
define_rfc6570_helpers(name, route, mod, set) click to toggle source
# 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 = {}) click to toggle source
# File lib/rails/rfc6570.rb, line 41
def to_rfc6570(opts = {})
  routes.to_h {|n, r| [n, r.to_rfc6570(opts)] }
end