Sha256: 54e3af260e3a393122a1451576f1ffd0a60be02647a164e7ca5ac8bb965fede9

Contents?: true

Size: 900 Bytes

Versions: 15

Compression:

Stored size: 900 Bytes

Contents

module Jets::Router
  class EngineMount
    def self.find_by(request_path: nil, engine: nil)
      new.find_by(request_path: request_path, engine: engine)
    end

    def find_by(request_path: nil, engine: nil)
      mount = if request_path
                find_by_request_path(request_path)
              elsif engine
                find_by_engine(engine)
              end

      return unless mount

      OpenStruct.new(at: mount[0], engine: mount[1])
    end

    def find_by_request_path(request_path)
      mounted_engines.find do |at, engine|
        request_path.starts_with?(at)
      end
    end

    def find_by_engine(engine)
      mounted = mounted_engines.find do |at, mounted_engine|
        mounted_engine == engine
      end
    end

    # Example mounted_engines: {"/blog"=>Blorgh::Engine}
    def mounted_engines
      Jets::Router::Dsl::Mount.mounted_engines
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/router/engine_mount.rb
jets-5.0.12 lib/jets/router/engine_mount.rb
jets-5.0.11 lib/jets/router/engine_mount.rb
jets-5.0.10 lib/jets/router/engine_mount.rb
jets-5.0.9 lib/jets/router/engine_mount.rb
jets-5.0.8 lib/jets/router/engine_mount.rb
jets-5.0.7 lib/jets/router/engine_mount.rb
jets-5.0.6 lib/jets/router/engine_mount.rb
jets-5.0.5 lib/jets/router/engine_mount.rb
jets-5.0.4 lib/jets/router/engine_mount.rb
jets-5.0.3 lib/jets/router/engine_mount.rb
jets-5.0.2 lib/jets/router/engine_mount.rb
jets-5.0.1 lib/jets/router/engine_mount.rb
jets-5.0.0 lib/jets/router/engine_mount.rb
jets-5.0.0.beta1 lib/jets/router/engine_mount.rb