Module: Databasium::EngineMount
- Defined in:
- lib/databasium/engine_mount.rb
Class Method Summary collapse
- .clear_mount_path_cache! ⇒ Object
- .databasium_route?(route) ⇒ Boolean
- .detected_mount_path ⇒ Object
- .find_mount_path_from_routes ⇒ Object
- .mount_path ⇒ Object
- .normalize_path(path) ⇒ Object
Class Method Details
.clear_mount_path_cache! ⇒ Object
14 15 16 |
# File 'lib/databasium/engine_mount.rb', line 14 def clear_mount_path_cache! @detected_mount_path = nil end |
.databasium_route?(route) ⇒ Boolean
27 28 29 30 |
# File 'lib/databasium/engine_mount.rb', line 27 def databasium_route?(route) app = route.app app == Databasium::Engine || (app.respond_to?(:app) && app.app == Databasium::Engine) end |
.detected_mount_path ⇒ Object
18 19 20 |
# File 'lib/databasium/engine_mount.rb', line 18 def detected_mount_path @detected_mount_path ||= find_mount_path_from_routes end |
.find_mount_path_from_routes ⇒ Object
22 23 24 25 |
# File 'lib/databasium/engine_mount.rb', line 22 def find_mount_path_from_routes route = Rails.application.routes.routes.find { |r| databasium_route?(r) } normalize_path(route&.path&.spec&.to_s) || "/databasium" end |
.mount_path ⇒ Object
7 8 9 10 11 12 |
# File 'lib/databasium/engine_mount.rb', line 7 def mount_path explicit = Rails.application.config.databasium&.mount_path return normalize_path(explicit) if explicit.present? detected_mount_path end |
.normalize_path(path) ⇒ Object
32 33 34 35 |
# File 'lib/databasium/engine_mount.rb', line 32 def normalize_path(path) cleaned = path.to_s.split("(").first.presence || "/" cleaned == "/" ? "/" : cleaned.chomp("/") end |