Class: Uchi::Routes
- Inherits:
-
Object
- Object
- Uchi::Routes
- Defined in:
- lib/uchi/routes.rb
Instance Method Summary collapse
- #draw_repository_routes(routes, at: default_at) ⇒ Object
- #draw_root_route(routes, repository:, at: default_at) ⇒ Object
-
#mount(host_routes, at: default_at) ⇒ Object
Mounts the Uchi engine routes onto the host application's routes.
-
#mount_as ⇒ Object
Returns the name to use when generating routing helper method names.
-
#mount_at ⇒ Object
Returns the path prefix for the routes, i.e.
Instance Method Details
#draw_repository_routes(routes, at: default_at) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/uchi/routes.rb', line 34 def draw_repository_routes(routes, at: default_at) repositories = Uchi::Repository.all repositories.each do |repository_class| resources_name = repository_class.controller_name routes.namespace(at, as: mount_as) do routes.resources(resources_name) end end draw_root_route(routes, at: at, repository: repositories.first) end |
#draw_root_route(routes, repository:, at: default_at) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/uchi/routes.rb', line 26 def draw_root_route(routes, repository:, at: default_at) return unless repository routes.namespace(at, as: mount_as) do routes.root to: "#{repository.controller_name}#index" end end |
#mount(host_routes, at: default_at) ⇒ Object
Mounts the Uchi engine routes onto the host application's routes.
Example usage in host application's routes.rb that install Uchi at /uchi:
Rails.application.routes.draw do Uchi.routes.mount(self) end
application's routes mapper.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/uchi/routes.rb', line 15 def mount(host_routes, at: default_at) @mount_at = (at || default_at).to_sym host_routes.mount( Uchi::Engine, as: mount_as, at: mount_at ) draw_repository_routes(host_routes, at: mount_at) end |
#mount_as ⇒ Object
Returns the name to use when generating routing helper method names
47 48 49 |
# File 'lib/uchi/routes.rb', line 47 def mount_as :uchi end |
#mount_at ⇒ Object
Returns the path prefix for the routes, i.e. the first URL segment where Uchi can be requested.
53 54 55 |
# File 'lib/uchi/routes.rb', line 53 def mount_at @mount_at ||= default_at end |