Sha256: d8cfc63656b4fb428a0e0b43cb4290380a3ff0683df0c68965d874ce2c0f89a7

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

# typed: strict
# frozen_string_literal: true

require "rails/railtie"
require "ruby_lsp_rails/rack_app"

module RubyLsp
  module Rails
    class Railtie < ::Rails::Railtie
      config.ruby_lsp_rails = ActiveSupport::OrderedOptions.new
      config.ruby_lsp_rails.server = true

      initializer "ruby_lsp_rails.setup" do |_app|
        config.after_initialize do |app|
          unless config.ruby_lsp_rails.server == false
            app.routes.prepend do
              T.bind(self, ActionDispatch::Routing::Mapper)
              mount(RackApp.new => RackApp::BASE_PATH)
            end
          end

          # If we start the app with `bin/rails console` then `Rails::Server` is not defined.
          if defined?(::Rails::Server)
            ssl_enable, host, port = ::Rails::Server::Options.new.parse!(ARGV).values_at(:SSLEnable, :Host, :Port)
            app_uri = "#{ssl_enable ? "https" : "http"}://#{host}:#{port}"
            app_uri_path = ::Rails.root.join("tmp", "app_uri.txt")
            app_uri_path.write(app_uri)

            at_exit do
              # The app_uri.txt file should only exist when the server is running. The extension uses its presence to
              # report if the server is running or not. If the server is not running, some of the extension features
              # will not be available.
              File.delete(app_uri_path) if File.exist?(app_uri_path)
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-lsp-rails-0.2.4 lib/ruby_lsp_rails/railtie.rb
ruby-lsp-rails-0.2.3 lib/ruby_lsp_rails/railtie.rb