Class: NREPL::Server
- Inherits:
-
Object
- Object
- NREPL::Server
- Defined in:
- lib/nrepl/server.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
(also: #debug?)
readonly
Returns the value of attribute debug.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(port: DEFAULT_PORT, host: DEFAULT_HOST, debug: false) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port: DEFAULT_PORT, host: DEFAULT_HOST, debug: false) ⇒ Server
20 21 22 23 24 25 26 |
# File 'lib/nrepl/server.rb', line 20 def initialize(port: DEFAULT_PORT, host: DEFAULT_HOST, debug: false) @port = port @host = host @debug = debug @connections = Set.new NREPL.class_variable_set(:@@connections, @connections) end |
Instance Attribute Details
#debug ⇒ Object (readonly) Also known as: debug?
Returns the value of attribute debug.
13 14 15 |
# File 'lib/nrepl/server.rb', line 13 def debug @debug end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
13 14 15 |
# File 'lib/nrepl/server.rb', line 13 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/nrepl/server.rb', line 13 def port @port end |
Class Method Details
.start(**kwargs) ⇒ Object
16 17 18 |
# File 'lib/nrepl/server.rb', line 16 def self.start(**kwargs) new(**kwargs).start end |
Instance Method Details
#start ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/nrepl/server.rb', line 34 def start puts "nREPL server started on port #{port} on host #{host} - nrepl://#{host}:#{port}" puts "Running in debug mode" if debug? record_port $stdout = FakeStdout.new(@connections, STDOUT, "out") $stderr = FakeStdout.new(@connections, STDERR, "err") Signal.trap("INT") { stop } Signal.trap("TERM") { stop } s = TCPServer.new(host, port) loop do Thread.start(s.accept) do |client| connection = Connection.new(client, debug: debug?) @connections << connection connection. @connections.delete(connection) end end ensure File.unlink(PORT_FILENAME) end |
#stop ⇒ Object
58 59 60 61 |
# File 'lib/nrepl/server.rb', line 58 def stop Thread.exit exit(0) end |