Class: RailsSpotlight::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/rails_spotlight/railtie.rb

Instance Method Summary collapse

Instance Method Details

#appObject



65
66
67
# File 'lib/rails_spotlight/railtie.rb', line 65

def app
  Rails.application
end

#insert_action_cable_helpersObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rails_spotlight/railtie.rb', line 27

def insert_action_cable_helpers
  return unless ::RailsSpotlight.config.action_cable_present?

  app.config.after_initialize do
    update_actioncable_allowed_request_origins!

    require 'rails_spotlight/channels/spotlight_channel' if ::RailsSpotlight.config.request_completed_broadcast_enabled?

    app.routes.draw { mount ActionCable.server => ::RailsSpotlight.config.action_cable_mount_path || '/cable' } if ::RailsSpotlight.config.auto_mount_action_cable?
  end
end

#insert_base_middlewaresObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rails_spotlight/railtie.rb', line 44

def insert_base_middlewares
  app.middleware.use ::RailsSpotlight::Middlewares::RequestHandler

  if defined? ActionDispatch::DebugExceptions
    app.middleware.insert_before ActionDispatch::DebugExceptions, ::RailsSpotlight::Middlewares::HeaderMarker, app.config
  else
    app.middleware.use ::RailsSpotlight::Middlewares::HeaderMarker, app.config
  end

  app.middleware.use ::RailsSpotlight::Middlewares::MainRequestHandler

  return unless ::RailsSpotlight.config.request_completed_broadcast_enabled?

  # app.middleware.insert_after ::RailsSpotlight::Middlewares::HeaderMarker, RailsSpotlight::Middlewares::RequestCompleted, app.config
  if defined? ActionDispatch::Executor
    app.middleware.insert_after ActionDispatch::Executor, ::RailsSpotlight::Middlewares::RequestCompleted, app.config
  else
    app.middleware.use ::RailsSpotlight::Middlewares::RequestCompleted
  end
end

#update_actioncable_allowed_request_origins!Object



39
40
41
42
# File 'lib/rails_spotlight/railtie.rb', line 39

def update_actioncable_allowed_request_origins!
  existing_origins = Array(app.config.action_cable.allowed_request_origins)
  app.config.action_cable.allowed_request_origins = existing_origins | [%r{\Achrome-extension://.*\z}]
end