Module: Rails::RFC6570::Extensions::NamedRouteCollection
- Defined in:
- lib/rails/rfc6570.rb
Instance Method Summary collapse
-
#add(name, route) ⇒ Object
(also: #[]=)
rubocop:enable all.
-
#define_rfc6570_helpers(name, route, mod, set) ⇒ Object
rubocop:disable MethodLength.
- #to_rfc6570(opts = {}) ⇒ Object
Instance Method Details
#add(name, route) ⇒ Object Also known as: []=
rubocop:enable all
80 81 82 83 |
# File 'lib/rails/rfc6570.rb', line 80 def add(name, route) super define_rfc6570_helpers name, route, @url_helpers_module, @url_helpers end |
#define_rfc6570_helpers(name, route, mod, set) ⇒ Object
rubocop:disable MethodLength
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 |
# File 'lib/rails/rfc6570.rb', line 49 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.merge(path_only: false)) end define_method(rfc6570_path_name) do |opts = {}| ::Rails::RFC6570.build_url_template(self, route, opts.merge(path_only: true)) end end set << rfc6570_name set << rfc6570_url_name set << rfc6570_path_name end |
#to_rfc6570(opts = {}) ⇒ Object
44 45 46 |
# File 'lib/rails/rfc6570.rb', line 44 def to_rfc6570(opts = {}) Hash[routes.map {|n, r| [n, r.to_rfc6570(opts)] }] end |