vegas 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,8 @@
1
+ == 0.1.8
2
+
3
+ * Add --no-proxy option for dealing with https and services behind proxies ( plukevdh)
4
+ * Update test suite for 1.9.2
5
+
1
6
  == 0.1.7
2
7
 
3
8
  * Exit with specific exit status (for monitoring/good unix citizen).
@@ -8,9 +8,8 @@ end
8
8
  $LOAD_PATH.unshift File.dirname(__FILE__)
9
9
 
10
10
  module Vegas
11
- VERSION = "0.1.7"
11
+ VERSION = "0.1.8"
12
12
  WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i)
13
-
13
+
14
14
  autoload :Runner, 'vegas/runner'
15
15
  end
16
-
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  if Vegas::WINDOWS
7
7
  begin
8
8
  require 'win32/process'
9
- rescue
9
+ rescue
10
10
  puts "Sorry, in order to use Vegas on Windows you need the win32-process gem:",
11
11
  "gem install win32-process"
12
12
  end
@@ -16,26 +16,26 @@ module Vegas
16
16
  class Runner
17
17
  attr_reader :app, :app_name, :filesystem_friendly_app_name, :quoted_app_name,
18
18
  :rack_handler, :port, :host, :options, :args
19
-
19
+
20
20
  ROOT_DIR = File.expand_path(File.join('~', '.vegas'))
21
21
  PORT = 5678
22
22
  HOST = WINDOWS ? 'localhost' : '0.0.0.0'
23
-
23
+
24
24
  def initialize(app, app_name, set_options = {}, runtime_args = ARGV, &block)
25
25
  @options = set_options || {}
26
-
26
+
27
27
  self.class.logger.level = options[:debug] ? Logger::DEBUG : Logger::INFO
28
-
28
+
29
29
  @app = app
30
30
  @app_name = app_name
31
-
31
+
32
32
  @filesystem_friendly_app_name = @app_name.gsub(/\W+/, "_")
33
33
  @quoted_app_name = "'#{app_name}'"
34
-
34
+
35
35
  @runtime_args = runtime_args
36
36
  @rack_handler = setup_rack_handler
37
-
38
- # load options from opt parser
37
+
38
+ # load options from opt parser
39
39
  @args = define_options do |opts|
40
40
  if block_given?
41
41
  opts.separator ''
@@ -48,7 +48,7 @@ module Vegas
48
48
  kill!
49
49
  exit!(0)
50
50
  end
51
-
51
+
52
52
  # Handle :before_run hook
53
53
  if (before_run = options.delete(:before_run)).respond_to?(:call)
54
54
  before_run.call(self)
@@ -56,24 +56,24 @@ module Vegas
56
56
 
57
57
  # Set app options
58
58
  @host = options[:host] || HOST
59
-
59
+
60
60
  if app.respond_to?(:set)
61
- app.set(options)
61
+ app.set(options)
62
62
  app.set(:vegas, self)
63
63
  end
64
-
64
+
65
65
  # Make sure app dir is setup
66
66
  FileUtils.mkdir_p(app_dir)
67
-
67
+
68
68
  return if options[:start] == false
69
-
69
+
70
70
  # evaluate the launch_path
71
71
  path = if options[:launch_path].respond_to?(:call)
72
72
  options[:launch_path].call(self)
73
73
  else
74
74
  options[:launch_path]
75
75
  end
76
-
76
+
77
77
  start(path)
78
78
  end
79
79
 
@@ -92,7 +92,7 @@ module Vegas
92
92
  def log_file
93
93
  options[:log_file] || File.join(app_dir, "#{filesystem_friendly_app_name}.log")
94
94
  end
95
-
95
+
96
96
  def url
97
97
  "http://#{host}:#{port}"
98
98
  end
@@ -116,7 +116,7 @@ module Vegas
116
116
  def find_port
117
117
  if @port = options[:port]
118
118
  announce_port_attempted
119
-
119
+
120
120
  unless port_open?
121
121
  logger.warn "Port #{port} is already in use. Please try another. " +
122
122
  "You can also omit the port flag, and we'll find one for you."
@@ -124,24 +124,28 @@ module Vegas
124
124
  else
125
125
  @port = PORT
126
126
  announce_port_attempted
127
-
127
+
128
128
  until port_open?
129
129
  @port += 1
130
130
  announce_port_attempted
131
131
  end
132
132
  end
133
133
  end
134
-
134
+
135
135
  def announce_port_attempted
136
136
  logger.info "trying port #{port}..."
137
137
  end
138
138
 
139
139
  def port_open?(check_url = nil)
140
140
  begin
141
- open(check_url || url)
141
+ check_url ||= url
142
+ options[:no_proxy] ? open(check_url, :proxy => nil) : open(check_url)
142
143
  false
143
144
  rescue Errno::ECONNREFUSED => e
144
145
  true
146
+ rescue Errno::EPERM => e
147
+ # catches the "Operation not permitted" under Cygwin
148
+ true
145
149
  end
146
150
  end
147
151
 
@@ -162,7 +166,7 @@ module Vegas
162
166
 
163
167
  def run!
164
168
  logger.info "Running with Rack handler: #{@rack_handler.inspect}"
165
-
169
+
166
170
  rack_handler.run app, :Host => host, :Port => port do |server|
167
171
  trap(kill_command) do
168
172
  ## Use thins' hard #stop! if available, otherwise just #stop
@@ -182,13 +186,13 @@ module Vegas
182
186
  else
183
187
  Process.daemon(true, true)
184
188
  end
185
-
189
+
186
190
  File.umask 0000
187
191
  FileUtils.touch log_file
188
192
  STDIN.reopen log_file
189
193
  STDOUT.reopen log_file, "a"
190
194
  STDERR.reopen log_file, "a"
191
-
195
+
192
196
  logger.debug "Child Process: #{Process.pid}"
193
197
 
194
198
  File.open(pid_file, 'w') {|f| f.write("#{Process.pid}") }
@@ -218,8 +222,8 @@ module Vegas
218
222
  logger.info "#{quoted_app_name} not running!"
219
223
  end
220
224
  end
221
-
222
- # Loads a config file at config_path and evals it in the context of the @app.
225
+
226
+ # Loads a config file at config_path and evals it in the context of the @app.
223
227
  def load_config_file(config_path)
224
228
  abort "Can not find config file at #{config_path}" if !File.readable?(config_path)
225
229
  config = File.read(config_path)
@@ -227,11 +231,11 @@ module Vegas
227
231
  config.sub!(/^__END__\n.*/, '')
228
232
  @app.module_eval(config)
229
233
  end
230
-
234
+
231
235
  def self.logger=(logger)
232
236
  @logger = logger
233
237
  end
234
-
238
+
235
239
  def self.logger
236
240
  @logger ||= LOGGER if defined?(LOGGER)
237
241
  if !@logger
@@ -245,16 +249,16 @@ module Vegas
245
249
  def logger
246
250
  self.class.logger
247
251
  end
248
-
252
+
249
253
  private
250
254
  def setup_rack_handler
251
255
  # First try to set Rack handler via a special hook we honor
252
256
  @rack_handler = if @app.respond_to?(:detect_rack_handler)
253
257
  @app.detect_rack_handler
254
-
258
+
255
259
  # If they aren't using our hook, try to use their @app.server settings
256
260
  elsif @app.respond_to?(:server) and @app.server
257
- # If :server isn't set, it returns an array of possibilities,
261
+ # If :server isn't set, it returns an array of possibilities,
258
262
  # sorted from most to least preferable.
259
263
  if @app.server.is_a?(Array)
260
264
  handler = nil
@@ -267,32 +271,32 @@ module Vegas
267
271
  end
268
272
  end
269
273
  handler
270
-
274
+
271
275
  # :server might be set explicitly to a single option like "mongrel"
272
276
  else
273
277
  Rack::Handler.get(@app.server)
274
278
  end
275
-
279
+
276
280
  # If all else fails, we'll use Thin
277
281
  else
278
282
  Rack::Handler::Thin
279
283
  end
280
284
  end
281
-
285
+
282
286
  def define_options
283
287
  OptionParser.new("", 24, ' ') do |opts|
284
- # TODO instead of app_name, we should determine the name of the script
288
+ # TODO instead of app_name, we should determine the name of the script
285
289
  # used to invoke Vegas and use that here
286
290
  opts.banner = "Usage: #{$0 || app_name} [options]"
287
291
 
288
292
  opts.separator ""
289
293
  opts.separator "Vegas options:"
290
294
 
291
- opts.on('-K', "--kill", "kill the running process and exit") {|k|
295
+ opts.on('-K', "--kill", "kill the running process and exit") {|k|
292
296
  @should_kill = true
293
297
  }
294
298
 
295
- opts.on('-S', "--status", "display the current running PID and URL then quit") {|s|
299
+ opts.on('-S', "--status", "display the current running PID and URL then quit") {|s|
296
300
  status
297
301
  exit!(0)
298
302
  }
@@ -309,6 +313,10 @@ module Vegas
309
313
  @options[:port] = port
310
314
  }
311
315
 
316
+ opts.on("-x", "--no-proxy", "ignore env proxy settings (e.g. http_proxy)") { |p|
317
+ @options[:no_proxy] = true
318
+ }
319
+
312
320
  opts.on("-e", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
313
321
  @options[:environment] = e
314
322
  }
@@ -320,27 +328,27 @@ module Vegas
320
328
  opts.on("-L", "--no-launch", "don't launch the browser") { |f|
321
329
  @options[:skip_launch] = true
322
330
  }
323
-
324
- opts.on('-d', "--debug", "raise the log level to :debug (default: :info)") {|s|
331
+
332
+ opts.on('-d', "--debug", "raise the log level to :debug (default: :info)") {|s|
325
333
  @options[:debug] = true
326
334
  }
327
-
328
- opts.on("--app-dir APP_DIR", "set the app dir where files are stored (default: ~/.vegas/#{filesystem_friendly_app_name})/)") {|app_dir|
335
+
336
+ opts.on("--app-dir APP_DIR", "set the app dir where files are stored (default: ~/.vegas/#{filesystem_friendly_app_name})/)") {|app_dir|
329
337
  @options[:app_dir] = app_dir
330
338
  }
331
-
332
- opts.on("-P", "--pid-file PID_FILE", "set the path to the pid file (default: app_dir/#{filesystem_friendly_app_name}.pid)") {|pid_file|
339
+
340
+ opts.on("-P", "--pid-file PID_FILE", "set the path to the pid file (default: app_dir/#{filesystem_friendly_app_name}.pid)") {|pid_file|
333
341
  @options[:pid_file] = pid_file
334
342
  }
335
-
336
- opts.on("--log-file LOG_FILE", "set the path to the log file (default: app_dir/#{filesystem_friendly_app_name}.log)") {|log_file|
343
+
344
+ opts.on("--log-file LOG_FILE", "set the path to the log file (default: app_dir/#{filesystem_friendly_app_name}.log)") {|log_file|
337
345
  @options[:log_file] = log_file
338
- }
339
-
340
- opts.on("--url-file URL_FILE", "set the path to the URL file (default: app_dir/#{filesystem_friendly_app_name}.url)") {|url_file|
346
+ }
347
+
348
+ opts.on("--url-file URL_FILE", "set the path to the URL file (default: app_dir/#{filesystem_friendly_app_name}.url)") {|url_file|
341
349
  @options[:url_file] = url_file
342
- }
343
-
350
+ }
351
+
344
352
  yield opts if block_given?
345
353
 
346
354
  opts.separator ""
@@ -375,5 +383,5 @@ module Vegas
375
383
  File.delete(pid_file) if File.exist?(pid_file)
376
384
  end
377
385
  end
378
-
386
+
379
387
  end
@@ -12,18 +12,18 @@ rescue LoadError
12
12
  dependencies.each {|f| require f }
13
13
  end
14
14
 
15
- require File.join(File.dirname(__FILE__), '..', 'lib', 'vegas.rb')
16
- require File.join(File.dirname(__FILE__), 'apps.rb')
15
+ require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'vegas.rb')
16
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'apps.rb')
17
17
 
18
18
 
19
19
  module TestHelper
20
-
20
+
21
21
  def vegas(*args, &block)
22
22
  Vegas::Runner.any_instance.stubs(:daemonize!).once
23
23
  Rack::Handler::Thin.stubs(:run).once
24
24
  @vegas = Vegas::Runner.new(*args, &block)
25
25
  end
26
-
26
+
27
27
  def body
28
28
  last_response.body.to_s
29
29
  end
@@ -31,14 +31,14 @@ module TestHelper
31
31
  def instance_of(klass)
32
32
  lambda {|obj| obj.is_a?(klass) }
33
33
  end
34
-
34
+
35
35
  def exist_as_file
36
36
  lambda {|obj| File.exist?(obj) }
37
37
  end
38
-
38
+
39
39
  def have_matching_file_content(content_regex)
40
- lambda {|obj|
41
- File.exist?(obj) && File.read(obj).match(content_regex)
40
+ lambda {|obj|
41
+ File.exist?(obj) && File.read(obj).match(content_regex)
42
42
  }
43
43
  end
44
44
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper.rb')
1
+ require File.join('.', File.dirname(__FILE__), 'test_helper.rb')
2
2
 
3
3
  Vegas::Runner.class_eval do
4
4
  remove_const :ROOT_DIR
@@ -27,11 +27,11 @@ describe 'Vegas::Runner' do
27
27
  it "sets app name" do
28
28
  @vegas.app_name.should == 'vegas_test_app_1'
29
29
  end
30
-
30
+
31
31
  it "sets quoted app name" do
32
32
  @vegas.quoted_app_name.should == "'vegas_test_app_1'"
33
33
  end
34
-
34
+
35
35
  it "sets filesystem friendly app name" do
36
36
  @vegas.filesystem_friendly_app_name.should == 'vegas_test_app_1'
37
37
  end
@@ -55,14 +55,14 @@ describe 'Vegas::Runner' do
55
55
  it "writes a url with the port" do
56
56
  @vegas.url_file.should have_matching_file_content(/0.0.0.0\:#{@vegas.port}/)
57
57
  end
58
-
58
+
59
59
  it "knows where to find the pid file" do
60
60
  @vegas.pid_file.should.equal \
61
61
  File.join(@vegas.app_dir, @vegas.filesystem_friendly_app_name + ".pid")
62
62
  # @vegas.pid_file.should exist_as_file
63
63
  end
64
64
  end
65
-
65
+
66
66
  describe 'basic usage with a funky app name' do
67
67
  before do
68
68
  Vegas::Runner.any_instance.expects(:system).once
@@ -76,15 +76,15 @@ describe 'Vegas::Runner' do
76
76
  it "sets app name" do
77
77
  @vegas.app_name.should == 'Funky YEAH!1!'
78
78
  end
79
-
79
+
80
80
  it "sets quoted app name" do
81
81
  @vegas.quoted_app_name.should == "'Funky YEAH!1!'"
82
82
  end
83
-
83
+
84
84
  it "sets filesystem friendly app name" do
85
85
  @vegas.filesystem_friendly_app_name.should == 'Funky_YEAH_1_'
86
86
  end
87
-
87
+
88
88
  it "stores options" do
89
89
  @vegas.options[:sessions].should.be.true
90
90
  end
@@ -104,14 +104,14 @@ describe 'Vegas::Runner' do
104
104
  it "writes a url with the port" do
105
105
  @vegas.url_file.should have_matching_file_content(/0.0.0.0\:#{@vegas.port}/)
106
106
  end
107
-
107
+
108
108
  it "knows where to find the pid file" do
109
109
  @vegas.pid_file.should.equal \
110
110
  File.join(@vegas.app_dir, @vegas.filesystem_friendly_app_name + ".pid")
111
111
  # @vegas.pid_file.should exist_as_file
112
112
  end
113
113
  end
114
-
114
+
115
115
  describe 'with a sinatra app using an explicit server setting' do
116
116
  before do
117
117
  TestApp1.set :server, "webrick"
@@ -119,7 +119,7 @@ describe 'Vegas::Runner' do
119
119
  Rack::Handler::WEBrick.stubs(:run)
120
120
  vegas(TestApp1, 'vegas_test_app_1', {:skip_launch => true, :sessions => true}, ["route","--debug"])
121
121
  end
122
-
122
+
123
123
  it 'sets the rack handler automaticaly' do
124
124
  @vegas.rack_handler.should == Rack::Handler::WEBrick
125
125
  end
@@ -129,36 +129,35 @@ describe 'Vegas::Runner' do
129
129
  before do
130
130
  vegas(RackApp1, 'rack_app_1', {:skip_launch => true, :sessions => true})
131
131
  end
132
-
132
+
133
133
  it "sets default rack handler to thin" do
134
134
  @vegas.rack_handler.should == Rack::Handler::Thin
135
- end
135
+ end
136
136
  end
137
-
138
- describe 'with a launch path specified as a proc' do
137
+
138
+ describe 'with a launch path specified as a proc' do
139
139
  it 'evaluates the proc in the context of the runner' do
140
140
  Vegas::Runner.any_instance.expects(:system).once.with {|s| s =~ /\?search\=blah$/ }
141
- vegas(TestApp2,
142
- 'vegas_test_app_2',
143
- {:launch_path => Proc.new {|r| "?search=#{r.args.first}" }},
141
+ vegas(TestApp2,
142
+ 'vegas_test_app_2',
143
+ {:launch_path => Proc.new {|r| "?search=#{r.args.first}" }},
144
144
  ["--debug", "blah"])
145
145
  @vegas.options[:launch_path].should.be instance_of(Proc)
146
- end
146
+ end
147
147
  end
148
-
148
+
149
149
  describe 'with a launch path specified as string' do
150
150
  it 'launches to the specific path' do
151
151
  Vegas::Runner.any_instance.expects(:system).once.with {|s| s =~ /\?search\=blah$/ }
152
- vegas(TestApp2,
153
- 'vegas_test_app_2',
154
- {:launch_path => "?search=blah"},
152
+ vegas(TestApp2,
153
+ 'vegas_test_app_2',
154
+ {:launch_path => "?search=blah"},
155
155
  ["--debug", "blah"])
156
156
  @vegas.options[:launch_path].should == "?search=blah"
157
157
  end
158
158
  end
159
-
159
+
160
160
 
161
161
  end
162
162
 
163
163
  end
164
-
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{vegas}
8
- s.version = "0.1.7"
8
+ s.version = "0.1.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Quint"]
12
- s.date = %q{2010-05-24}
12
+ s.date = %q{2010-10-11}
13
13
  s.description = %q{Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps. It includes a class Vegas::Runner that wraps Rack/Sinatra applications and provides a simple command line interface and launching mechanism.}
14
14
  s.email = ["aaron@quirkey.com"]
15
15
  s.extra_rdoc_files = [
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
36
36
  s.rdoc_options = ["--charset=UTF-8"]
37
37
  s.require_paths = ["lib"]
38
38
  s.rubyforge_project = %q{quirkey}
39
- s.rubygems_version = %q{1.3.6}
39
+ s.rubygems_version = %q{1.3.7}
40
40
  s.summary = %q{Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps.}
41
41
  s.test_files = [
42
42
  "test/apps.rb",
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
50
  s.specification_version = 3
51
51
 
52
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
53
  s.add_runtime_dependency(%q<rack>, [">= 1.0.0"])
54
54
  s.add_development_dependency(%q<mocha>, ["~> 0.9.8"])
55
55
  s.add_development_dependency(%q<bacon>, ["~> 1.1.0"])
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 7
9
- version: 0.1.7
8
+ - 8
9
+ version: 0.1.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aaron Quint
@@ -14,13 +14,14 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-24 00:00:00 -04:00
17
+ date: 2010-10-11 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rack
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
@@ -35,6 +36,7 @@ dependencies:
35
36
  name: mocha
36
37
  prerelease: false
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
38
40
  requirements:
39
41
  - - ~>
40
42
  - !ruby/object:Gem::Version
@@ -49,6 +51,7 @@ dependencies:
49
51
  name: bacon
50
52
  prerelease: false
51
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
52
55
  requirements:
53
56
  - - ~>
54
57
  - !ruby/object:Gem::Version
@@ -63,6 +66,7 @@ dependencies:
63
66
  name: sinatra
64
67
  prerelease: false
65
68
  requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
66
70
  requirements:
67
71
  - - ~>
68
72
  - !ruby/object:Gem::Version
@@ -108,6 +112,7 @@ rdoc_options:
108
112
  require_paths:
109
113
  - lib
110
114
  required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
111
116
  requirements:
112
117
  - - ">="
113
118
  - !ruby/object:Gem::Version
@@ -115,6 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
120
  - 0
116
121
  version: "0"
117
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
118
124
  requirements:
119
125
  - - ">="
120
126
  - !ruby/object:Gem::Version
@@ -124,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
130
  requirements: []
125
131
 
126
132
  rubyforge_project: quirkey
127
- rubygems_version: 1.3.6
133
+ rubygems_version: 1.3.7
128
134
  signing_key:
129
135
  specification_version: 3
130
136
  summary: Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps.