class Gearhead::Router
Attributes
router[R]
Public Class Methods
new(router:)
click to toggle source
# File lib/gearhead/router.rb, line 5 def initialize(router:) @router = router end
Public Instance Methods
apply()
click to toggle source
# File lib/gearhead/router.rb, line 9 def apply if Gearhead.config.automount.enabled? define_automount_route end define_gear_routes end
build_action(action)
click to toggle source
# File lib/gearhead/router.rb, line 50 def build_action(action) build_route(action.verbs, action.name) end
build_route(verbs, *args)
click to toggle source
# File lib/gearhead/router.rb, line 54 def build_route(verbs, *args) Array.wrap(verbs).each { |verb| router.send(verb, *args) } end
define_actions(gear)
click to toggle source
# File lib/gearhead/router.rb, line 28 def define_actions(gear) @router.member do gear._gear_member_actions.values.each do |custom_action| custom_action.verbs.each do |verb| args = [custom_action.name, to: 'gearhead/gears#member_action', defaults: { member_action: custom_action.name }] router.send(verb, *args) end end end @router.collection do gear._gear_collection_actions.values.each do |custom_action| custom_action.verbs.each do |verb| args = [custom_action.name, to: 'gearhead/gears#collection_action', defaults: { collection_action: custom_action.name }] router.send(verb, *args) end end end end
define_automount_route()
click to toggle source
# File lib/gearhead/router.rb, line 16 def define_automount_route @router.resources :gears, path: [::Gearhead.config.endpoint, ":resource_class"].join("/"), controller: "gearhead/gears", param: :resource_id end
define_gear_routes()
click to toggle source
# File lib/gearhead/router.rb, line 20 def define_gear_routes ::Gearhead.registry.all.each do |thing| @router.resources thing.resource.model_name.route_key, path: [::Gearhead.config.endpoint, thing.path].join("/"), controller: "gearhead/gears", param: :resource_id, defaults: { resource_class: thing.resource.model_name.route_key } do define_actions(thing) end end end