rsense-server 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +14 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +1 -0
  6. data/README.md +51 -0
  7. data/Rakefile +9 -0
  8. data/bin/_rsense.rb +115 -0
  9. data/config/puma.rb +2 -0
  10. data/lib/rsense/server/code.rb +38 -0
  11. data/lib/rsense/server/command/completion_result.rb +11 -0
  12. data/lib/rsense/server/command/special_meth.rb +18 -0
  13. data/lib/rsense/server/command/type_inference_method.rb +24 -0
  14. data/lib/rsense/server/command.rb +239 -0
  15. data/lib/rsense/server/config.rb +70 -0
  16. data/lib/rsense/server/gem_path.rb +18 -0
  17. data/lib/rsense/server/listeners/find_definition_event_listener.rb +91 -0
  18. data/lib/rsense/server/listeners/where_event_listener.rb +39 -0
  19. data/lib/rsense/server/load_path.rb +62 -0
  20. data/lib/rsense/server/options.rb +85 -0
  21. data/lib/rsense/server/parser.rb +17 -0
  22. data/lib/rsense/server/path_info.rb +17 -0
  23. data/lib/rsense/server/project.rb +24 -0
  24. data/lib/rsense/server/version.rb +5 -0
  25. data/lib/rsense/server.rb +18 -0
  26. data/rsense-server.gemspec +35 -0
  27. data/spec/fixtures/config_fixture/.rsense +4 -0
  28. data/spec/fixtures/deeply/nested/thing.rb +0 -0
  29. data/spec/fixtures/find_def_sample.json +10 -0
  30. data/spec/fixtures/sample.json +10 -0
  31. data/spec/fixtures/test_gem/.gitignore +22 -0
  32. data/spec/fixtures/test_gem/Gemfile +4 -0
  33. data/spec/fixtures/test_gem/LICENSE.txt +22 -0
  34. data/spec/fixtures/test_gem/README.md +29 -0
  35. data/spec/fixtures/test_gem/Rakefile +2 -0
  36. data/spec/fixtures/test_gem/lib/sample/version.rb +3 -0
  37. data/spec/fixtures/test_gem/lib/sample.rb +16 -0
  38. data/spec/fixtures/test_gem/sample.gemspec +23 -0
  39. data/spec/fixtures/test_gem/test.json +10 -0
  40. data/spec/rsense/server/code_spec.rb +44 -0
  41. data/spec/rsense/server/command/special_meth_spec.rb +23 -0
  42. data/spec/rsense/server/command_spec.rb +108 -0
  43. data/spec/rsense/server/config_spec.rb +27 -0
  44. data/spec/rsense/server/gem_path_spec.rb +16 -0
  45. data/spec/rsense/server/load_path_spec.rb +63 -0
  46. data/spec/rsense/server/options_spec.rb +33 -0
  47. data/spec/rsense/server/path_info_spec.rb +11 -0
  48. data/spec/rsense/server/project_spec.rb +18 -0
  49. data/spec/rsense/server_spec.rb +7 -0
  50. data/spec/spec_helper.rb +16 -0
  51. data/vendor/gems/puma-2.8.2-java/COPYING +55 -0
  52. data/vendor/gems/puma-2.8.2-java/DEPLOYMENT.md +92 -0
  53. data/vendor/gems/puma-2.8.2-java/Gemfile +17 -0
  54. data/vendor/gems/puma-2.8.2-java/History.txt +532 -0
  55. data/vendor/gems/puma-2.8.2-java/LICENSE +26 -0
  56. data/vendor/gems/puma-2.8.2-java/Manifest.txt +68 -0
  57. data/vendor/gems/puma-2.8.2-java/README.md +251 -0
  58. data/vendor/gems/puma-2.8.2-java/Rakefile +158 -0
  59. data/vendor/gems/puma-2.8.2-java/bin/puma +10 -0
  60. data/vendor/gems/puma-2.8.2-java/bin/puma-wild +17 -0
  61. data/vendor/gems/puma-2.8.2-java/bin/pumactl +12 -0
  62. data/vendor/gems/puma-2.8.2-java/docs/config.md +0 -0
  63. data/vendor/gems/puma-2.8.2-java/docs/nginx.md +80 -0
  64. data/vendor/gems/puma-2.8.2-java/docs/signals.md +42 -0
  65. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/PumaHttp11Service.java +17 -0
  66. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/ext_help.h +15 -0
  67. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/extconf.rb +8 -0
  68. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.c +1225 -0
  69. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.h +64 -0
  70. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.java.rl +161 -0
  71. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.rl +146 -0
  72. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser_common.rl +54 -0
  73. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/io_buffer.c +155 -0
  74. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/mini_ssl.c +195 -0
  75. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/Http11.java +225 -0
  76. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/Http11Parser.java +488 -0
  77. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/MiniSSL.java +289 -0
  78. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/puma_http11.c +491 -0
  79. data/vendor/gems/puma-2.8.2-java/lib/puma/accept_nonblock.rb +23 -0
  80. data/vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb +59 -0
  81. data/vendor/gems/puma-2.8.2-java/lib/puma/binder.rb +298 -0
  82. data/vendor/gems/puma-2.8.2-java/lib/puma/capistrano.rb +86 -0
  83. data/vendor/gems/puma-2.8.2-java/lib/puma/cli.rb +587 -0
  84. data/vendor/gems/puma-2.8.2-java/lib/puma/client.rb +289 -0
  85. data/vendor/gems/puma-2.8.2-java/lib/puma/cluster.rb +389 -0
  86. data/vendor/gems/puma-2.8.2-java/lib/puma/compat.rb +18 -0
  87. data/vendor/gems/puma-2.8.2-java/lib/puma/configuration.rb +377 -0
  88. data/vendor/gems/puma-2.8.2-java/lib/puma/const.rb +165 -0
  89. data/vendor/gems/puma-2.8.2-java/lib/puma/control_cli.rb +251 -0
  90. data/vendor/gems/puma-2.8.2-java/lib/puma/daemon_ext.rb +25 -0
  91. data/vendor/gems/puma-2.8.2-java/lib/puma/delegation.rb +11 -0
  92. data/vendor/gems/puma-2.8.2-java/lib/puma/detect.rb +4 -0
  93. data/vendor/gems/puma-2.8.2-java/lib/puma/events.rb +130 -0
  94. data/vendor/gems/puma-2.8.2-java/lib/puma/io_buffer.rb +7 -0
  95. data/vendor/gems/puma-2.8.2-java/lib/puma/java_io_buffer.rb +45 -0
  96. data/vendor/gems/puma-2.8.2-java/lib/puma/jruby_restart.rb +83 -0
  97. data/vendor/gems/puma-2.8.2-java/lib/puma/minissl.rb +148 -0
  98. data/vendor/gems/puma-2.8.2-java/lib/puma/null_io.rb +34 -0
  99. data/vendor/gems/puma-2.8.2-java/lib/puma/puma_http11.jar +0 -0
  100. data/vendor/gems/puma-2.8.2-java/lib/puma/rack_default.rb +7 -0
  101. data/vendor/gems/puma-2.8.2-java/lib/puma/rack_patch.rb +45 -0
  102. data/vendor/gems/puma-2.8.2-java/lib/puma/reactor.rb +183 -0
  103. data/vendor/gems/puma-2.8.2-java/lib/puma/runner.rb +146 -0
  104. data/vendor/gems/puma-2.8.2-java/lib/puma/server.rb +801 -0
  105. data/vendor/gems/puma-2.8.2-java/lib/puma/single.rb +102 -0
  106. data/vendor/gems/puma-2.8.2-java/lib/puma/tcp_logger.rb +32 -0
  107. data/vendor/gems/puma-2.8.2-java/lib/puma/thread_pool.rb +185 -0
  108. data/vendor/gems/puma-2.8.2-java/lib/puma/util.rb +9 -0
  109. data/vendor/gems/puma-2.8.2-java/lib/puma.rb +14 -0
  110. data/vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb +66 -0
  111. data/vendor/gems/puma-2.8.2-java/puma.gemspec +55 -0
  112. data/vendor/gems/puma-2.8.2-java/test/test_app_status.rb +92 -0
  113. data/vendor/gems/puma-2.8.2-java/test/test_cli.rb +173 -0
  114. data/vendor/gems/puma-2.8.2-java/test/test_config.rb +26 -0
  115. data/vendor/gems/puma-2.8.2-java/test/test_http10.rb +27 -0
  116. data/vendor/gems/puma-2.8.2-java/test/test_http11.rb +144 -0
  117. data/vendor/gems/puma-2.8.2-java/test/test_integration.rb +165 -0
  118. data/vendor/gems/puma-2.8.2-java/test/test_iobuffer.rb +38 -0
  119. data/vendor/gems/puma-2.8.2-java/test/test_minissl.rb +25 -0
  120. data/vendor/gems/puma-2.8.2-java/test/test_null_io.rb +31 -0
  121. data/vendor/gems/puma-2.8.2-java/test/test_persistent.rb +238 -0
  122. data/vendor/gems/puma-2.8.2-java/test/test_puma_server.rb +323 -0
  123. data/vendor/gems/puma-2.8.2-java/test/test_rack_handler.rb +10 -0
  124. data/vendor/gems/puma-2.8.2-java/test/test_rack_server.rb +141 -0
  125. data/vendor/gems/puma-2.8.2-java/test/test_tcp_rack.rb +42 -0
  126. data/vendor/gems/puma-2.8.2-java/test/test_thread_pool.rb +156 -0
  127. data/vendor/gems/puma-2.8.2-java/test/test_unix_socket.rb +39 -0
  128. data/vendor/gems/puma-2.8.2-java/test/test_ws.rb +89 -0
  129. data/vendor/gems/puma-2.8.2-java/tools/jungle/README.md +9 -0
  130. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/README.md +54 -0
  131. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/puma +332 -0
  132. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/run-puma +3 -0
  133. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/README.md +61 -0
  134. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/puma-manager.conf +31 -0
  135. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/puma.conf +63 -0
  136. data/vendor/gems/puma-2.8.2-java/tools/trickletest.rb +45 -0
  137. metadata +389 -0
@@ -0,0 +1,34 @@
1
+ module Puma
2
+
3
+ # Provides an IO-like object that always appears to contain no data.
4
+ # Used as the value for rack.input when the request has no body.
5
+ #
6
+ class NullIO
7
+ # Always returns nil
8
+ #
9
+ def gets
10
+ nil
11
+ end
12
+
13
+ # Never yields
14
+ #
15
+ def each
16
+ end
17
+
18
+ # Mimics IO#read with no data
19
+ #
20
+ def read(count=nil,buffer=nil)
21
+ (count && count > 0) ? nil : ""
22
+ end
23
+
24
+ # Does nothing
25
+ #
26
+ def rewind
27
+ end
28
+
29
+ # Does nothing
30
+ #
31
+ def close
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'rack/handler/puma'
2
+
3
+ module Rack::Handler
4
+ def self.default(options = {})
5
+ Rack::Handler::Puma
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ require 'rack/commonlogger'
2
+
3
+ module Rack
4
+ # Patch CommonLogger to use after_reply.
5
+ #
6
+ # Simply request this file and CommonLogger will be a bit more
7
+ # efficient.
8
+ class CommonLogger
9
+ remove_method :call
10
+
11
+ def call(env)
12
+ began_at = Time.now
13
+ status, header, body = @app.call(env)
14
+ header = Utils::HeaderHash.new(header)
15
+
16
+ # If we've been hijacked, then output a special line
17
+ if env['rack.hijack_io']
18
+ log_hijacking(env, 'HIJACK', header, began_at)
19
+ elsif ary = env['rack.after_reply']
20
+ ary << lambda { log(env, status, header, began_at) }
21
+ else
22
+ body = BodyProxy.new(body) { log(env, status, header, began_at) }
23
+ end
24
+
25
+ [status, header, body]
26
+ end
27
+
28
+ HIJACK_FORMAT = %{%s - %s [%s] "%s %s%s %s" HIJACKED -1 %0.4f\n}
29
+
30
+ def log_hijacking(env, status, header, began_at)
31
+ now = Time.now
32
+
33
+ logger = @logger || env['rack.errors']
34
+ logger.write HIJACK_FORMAT % [
35
+ env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
36
+ env["REMOTE_USER"] || "-",
37
+ now.strftime("%d/%b/%Y %H:%M:%S"),
38
+ env["REQUEST_METHOD"],
39
+ env["PATH_INFO"],
40
+ env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
41
+ env["HTTP_VERSION"],
42
+ now - began_at ]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,183 @@
1
+ require 'puma/util'
2
+
3
+ module Puma
4
+ class Reactor
5
+ DefaultSleepFor = 5
6
+
7
+ def initialize(server, app_pool)
8
+ @server = server
9
+ @events = server.events
10
+ @app_pool = app_pool
11
+
12
+ @mutex = Mutex.new
13
+ @ready, @trigger = Puma::Util.pipe
14
+ @input = []
15
+ @sleep_for = DefaultSleepFor
16
+ @timeouts = []
17
+
18
+ @sockets = [@ready]
19
+ end
20
+
21
+ private
22
+
23
+ def run_internal
24
+ sockets = @sockets
25
+
26
+ while true
27
+ begin
28
+ ready = IO.select sockets, nil, nil, @sleep_for
29
+ rescue IOError => e
30
+ if sockets.any? { |socket| socket.closed? }
31
+ STDERR.puts "Error in select: #{e.message} (#{e.class})"
32
+ STDERR.puts e.backtrace
33
+ sockets = sockets.reject { |socket| socket.closed? }
34
+ retry
35
+ else
36
+ raise
37
+ end
38
+ end
39
+
40
+ if ready and reads = ready[0]
41
+ reads.each do |c|
42
+ if c == @ready
43
+ @mutex.synchronize do
44
+ case @ready.read(1)
45
+ when "*"
46
+ sockets += @input
47
+ @input.clear
48
+ when "c"
49
+ sockets.delete_if do |s|
50
+ if s == @ready
51
+ false
52
+ else
53
+ s.close
54
+ true
55
+ end
56
+ end
57
+ when "!"
58
+ return
59
+ end
60
+ end
61
+ else
62
+ # We have to be sure to remove it from the timeout
63
+ # list or we'll accidentally close the socket when
64
+ # it's in use!
65
+ if c.timeout_at
66
+ @mutex.synchronize do
67
+ @timeouts.delete c
68
+ end
69
+ end
70
+
71
+ begin
72
+ if c.try_to_finish
73
+ @app_pool << c
74
+ sockets.delete c
75
+ end
76
+
77
+ # The client doesn't know HTTP well
78
+ rescue HttpParserError => e
79
+ c.write_400
80
+ c.close
81
+
82
+ sockets.delete c
83
+
84
+ @events.parse_error @server, c.env, e
85
+ rescue StandardError => e
86
+ c.write_500
87
+ c.close
88
+
89
+ sockets.delete c
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ unless @timeouts.empty?
96
+ @mutex.synchronize do
97
+ now = Time.now
98
+
99
+ while @timeouts.first.timeout_at < now
100
+ c = @timeouts.shift
101
+ c.write_408 if c.in_data_phase
102
+ c.close
103
+ sockets.delete c
104
+
105
+ break if @timeouts.empty?
106
+ end
107
+
108
+ calculate_sleep
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ public
115
+
116
+ def run
117
+ run_internal
118
+ ensure
119
+ @trigger.close
120
+ @ready.close
121
+ end
122
+
123
+ def run_in_thread
124
+ @thread = Thread.new do
125
+ begin
126
+ run_internal
127
+ rescue StandardError => e
128
+ STDERR.puts "Error in reactor loop escaped: #{e.message} (#{e.class})"
129
+ STDERR.puts e.backtrace
130
+ retry
131
+ ensure
132
+ @trigger.close
133
+ @ready.close
134
+ end
135
+ end
136
+ end
137
+
138
+ def calculate_sleep
139
+ if @timeouts.empty?
140
+ @sleep_for = DefaultSleepFor
141
+ else
142
+ diff = @timeouts.first.timeout_at.to_f - Time.now.to_f
143
+
144
+ if diff < 0.0
145
+ @sleep_for = 0
146
+ else
147
+ @sleep_for = diff
148
+ end
149
+ end
150
+ end
151
+
152
+ def add(c)
153
+ @mutex.synchronize do
154
+ @input << c
155
+ @trigger << "*"
156
+
157
+ if c.timeout_at
158
+ @timeouts << c
159
+ @timeouts.sort! { |a,b| a.timeout_at <=> b.timeout_at }
160
+
161
+ calculate_sleep
162
+ end
163
+ end
164
+ end
165
+
166
+ # Close all watched sockets and clear them from being watched
167
+ def clear!
168
+ begin
169
+ @trigger << "c"
170
+ rescue IOError
171
+ end
172
+ end
173
+
174
+ def shutdown
175
+ begin
176
+ @trigger << "!"
177
+ rescue IOError
178
+ end
179
+
180
+ @thread.join
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,146 @@
1
+ module Puma
2
+ class Runner
3
+ def initialize(cli)
4
+ @cli = cli
5
+ @options = cli.options
6
+ @app = nil
7
+ @control = nil
8
+ end
9
+
10
+ def daemon?
11
+ @options[:daemon]
12
+ end
13
+
14
+ def development?
15
+ @options[:environment] == "development"
16
+ end
17
+
18
+ def log(str)
19
+ @cli.log str
20
+ end
21
+
22
+ def error(str)
23
+ @cli.error str
24
+ end
25
+
26
+ def before_restart
27
+ @control.stop(true) if @control
28
+ end
29
+
30
+ def start_control
31
+ str = @options[:control_url]
32
+ return unless str
33
+
34
+ require 'puma/app/status'
35
+
36
+ uri = URI.parse str
37
+
38
+ app = Puma::App::Status.new @cli
39
+
40
+ if token = @options[:control_auth_token]
41
+ app.auth_token = token unless token.empty? or token == :none
42
+ end
43
+
44
+ control = Puma::Server.new app, @cli.events
45
+ control.min_threads = 0
46
+ control.max_threads = 1
47
+
48
+ case uri.scheme
49
+ when "tcp"
50
+ log "* Starting control server on #{str}"
51
+ control.add_tcp_listener uri.host, uri.port
52
+ when "unix"
53
+ log "* Starting control server on #{str}"
54
+ path = "#{uri.host}#{uri.path}"
55
+
56
+ control.add_unix_listener path
57
+ else
58
+ error "Invalid control URI: #{str}"
59
+ end
60
+
61
+ control.run
62
+ @control = control
63
+ end
64
+
65
+ def ruby_engine
66
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
67
+ "ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
68
+ else
69
+ "#{RUBY_ENGINE} #{RUBY_VERSION}"
70
+ end
71
+ end
72
+
73
+ def output_header(mode)
74
+ min_t = @options[:min_threads]
75
+ max_t = @options[:max_threads]
76
+
77
+ log "Puma starting in #{mode} mode..."
78
+ log "* Version #{Puma::Const::PUMA_VERSION} (#{ruby_engine}), codename: #{Puma::Const::CODE_NAME}"
79
+ log "* Min threads: #{min_t}, max threads: #{max_t}"
80
+ log "* Environment: #{ENV['RACK_ENV']}"
81
+
82
+ if @options[:mode] == :tcp
83
+ log "* Mode: Lopez Express (tcp)"
84
+ end
85
+ end
86
+
87
+ def redirect_io
88
+ stdout = @options[:redirect_stdout]
89
+ stderr = @options[:redirect_stderr]
90
+ append = @options[:redirect_append]
91
+
92
+ if stdout
93
+ STDOUT.reopen stdout, (append ? "a" : "w")
94
+ STDOUT.sync = true
95
+ STDOUT.puts "=== puma startup: #{Time.now} ==="
96
+ end
97
+
98
+ if stderr
99
+ STDERR.reopen stderr, (append ? "a" : "w")
100
+ STDERR.sync = true
101
+ STDERR.puts "=== puma startup: #{Time.now} ==="
102
+ end
103
+ end
104
+
105
+ def load_and_bind
106
+ unless @cli.config.app_configured?
107
+ error "No application configured, nothing to run"
108
+ exit 1
109
+ end
110
+
111
+ # Load the app before we daemonize.
112
+ begin
113
+ @app = @cli.config.app
114
+ rescue Exception => e
115
+ log "! Unable to load application"
116
+ raise e
117
+ end
118
+
119
+ @cli.binder.parse @options[:binds], self
120
+ end
121
+
122
+ def app
123
+ @app ||= @cli.config.app
124
+ end
125
+
126
+ def start_server
127
+ min_t = @options[:min_threads]
128
+ max_t = @options[:max_threads]
129
+
130
+ server = Puma::Server.new app, @cli.events, @options
131
+ server.min_threads = min_t
132
+ server.max_threads = max_t
133
+ server.inherit_binder @cli.binder
134
+
135
+ if @options[:mode] == :tcp
136
+ server.tcp_mode!
137
+ end
138
+
139
+ unless development?
140
+ server.leak_stack_on_error = false
141
+ end
142
+
143
+ server
144
+ end
145
+ end
146
+ end