Class: RiderServer::Services::Rails

Inherits:
RiderServer::Service show all
Defined in:
lib/rider_server/services/rails.rb

Instance Method Summary collapse

Methods inherited from RiderServer::Service

service_name

Constructor Details

#initialize(session) ⇒ Rails

Returns a new instance of Rails.



15
16
17
18
# File 'lib/rider_server/services/rails.rb', line 15

def initialize(session)
  @session = session
  super
end

Instance Method Details

#start(stream_id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rider_server/services/rails.rb', line 20

def start(stream_id)
  @stream_id = stream_id

  # Suck it ruby, i can define constants at runtime
  eval('::APP_PATH = File.expand_path("./config/application", Dir.pwd)', TOPLEVEL_BINDING, __FILE__, __LINE__)
  nputs "Starting Rails Server..."

  @thread = Thread.new do
    require File.expand_path("./config/boot", Dir.pwd)
    require "rails/command"
    require "rails/commands/server/server_command"

    set_application_directory!

    ::Rails::Server.new(server_options).tap do |server|
      require APP_PATH

      Dir.chdir(::Rails.application.root)

      unless Rails.application.config.middleware.include?(Services::RailsExceptionMiddleware)
        ::Rails.application.config.middleware.insert_after(
          ActionDispatch::DebugExceptions, Services::RailsExceptionMiddleware, @stream_id, @session
        )
      end

      if server.serveable?
        nputs_boot_information(server.server, server.served_url)
        after_stop_callback = -> { nputs "Rails Server Exiting..." }
        server.start(after_stop_callback)
      else
        nputs rack_server_suggestion(options[:using])
      end
    end
  rescue => e
    @session.add_exception(stream_id, e)
    nputs "Error starting Rails Server: #{e.message}"
  end
end

#statusObject



63
64
65
66
67
68
69
# File 'lib/rider_server/services/rails.rb', line 63

def status
  if @thread&.alive?
    :running
  else
    :stopped
  end
end

#stopObject



59
60
61
# File 'lib/rider_server/services/rails.rb', line 59

def stop
  @thread.raise(Interrupt)
end