Class: Jets::Router::EngineMount

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/router/engine_mount.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by(request_path: nil, engine: nil) ⇒ Object



3
4
5
# File 'lib/jets/router/engine_mount.rb', line 3

def self.find_by(request_path: nil, engine: nil)
  new.find_by(request_path: request_path, engine: engine)
end

Instance Method Details

#find_by(request_path: nil, engine: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jets/router/engine_mount.rb', line 7

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

#find_by_engine(engine) ⇒ Object



25
26
27
28
29
# File 'lib/jets/router/engine_mount.rb', line 25

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

#find_by_request_path(request_path) ⇒ Object



19
20
21
22
23
# File 'lib/jets/router/engine_mount.rb', line 19

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

#mounted_enginesObject

Example mounted_engines: Jets::Router::EngineMount.“/blog”=>Blorgh“/blog”=>Blorgh::Engine



32
33
34
# File 'lib/jets/router/engine_mount.rb', line 32

def mounted_engines
  Jets::Router::Dsl::Mount.mounted_engines
end