Class: Trainspotter::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/trainspotter/engine.rb

Class Method Summary collapse

Class Method Details

.engine_mount_pathObject



34
35
36
37
38
39
# File 'lib/trainspotter/engine.rb', line 34

def self.engine_mount_path
  route = Rails.application.routes.routes.find do |r|
    r.app.respond_to?(:app) && r.app.app == Trainspotter::Engine
  end
  route&.path&.spec&.to_s&.chomp("(.:format)")
end

.silence_engine_requestsObject



24
25
26
27
28
29
30
31
32
# File 'lib/trainspotter/engine.rb', line 24

def self.silence_engine_requests
  if mount_path = engine_mount_path
    Rails.application.config.middleware.insert_before(
      Rails::Rack::Logger,
      Rails::Rack::SilenceRequest,
      path: %r{^#{Regexp.escape(mount_path)}}
    )
  end
end

.start_background_workerObject



41
42
43
44
45
46
47
48
49
# File 'lib/trainspotter/engine.rb', line 41

def self.start_background_worker
  Trainspotter::BackgroundWorker.start(
    interval: Trainspotter.background_worker_interval,
    lock_path: Rails.root.join("tmp", "trainspotter.lock"),
    logger: Rails.logger
  ) do
    Trainspotter::IngestJob.new.perform
  end
end