module Dry::RoutingHelpers
Public Instance Methods
collection_path(resource)
click to toggle source
# File lib/dry/routing_helpers.rb, line 3 def collection_path resource send "#{base_path resource, plural: true}_path" end
edit_path(record)
click to toggle source
# File lib/dry/routing_helpers.rb, line 15 def edit_path record send "edit_#{base_path record.class}_path", *([@parent, record].compact) end
form_arguments(record)
click to toggle source
# File lib/dry/routing_helpers.rb, line 24 def form_arguments record [*current_namespace, @parent, record].compact end
new_path(resource)
click to toggle source
# File lib/dry/routing_helpers.rb, line 11 def new_path resource send "new_#{base_path resource}_path" end
record_path(record)
click to toggle source
# File lib/dry/routing_helpers.rb, line 7 def record_path record send "#{base_path record.class}_path", *([@parent, record].compact) end
relation_path(record, relation)
click to toggle source
# File lib/dry/routing_helpers.rb, line 19 def relation_path record, relation send "#{base_path record.class}_#{relation.model_name.route_key}_path", record end
Private Instance Methods
base_path(klass, plural: false)
click to toggle source
# File lib/dry/routing_helpers.rb, line 34 def base_path klass, plural: false path = [*current_namespace].flatten path << parent_class.model_name.singular_route_key if parent? path << klass.model_name.send(plural ? :route_key : :singular_route_key) path * '_' end
current_namespace()
click to toggle source
# File lib/dry/routing_helpers.rb, line 30 def current_namespace (controller_path.split('/') - [controller_name]).map &:to_sym end
parent?()
click to toggle source
# File lib/dry/routing_helpers.rb, line 41 def parent? !!@parent end
parent_class()
click to toggle source
# File lib/dry/routing_helpers.rb, line 45 def parent_class @parent ? @parent.class : nil end