vegas 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  begin
2
2
  require 'rack'
3
+ require 'rbconfig'
3
4
  rescue LoadError
4
5
  require 'rubygems'
5
6
  require 'rack'
@@ -8,8 +9,10 @@ end
8
9
  $LOAD_PATH.unshift File.dirname(__FILE__)
9
10
 
10
11
  module Vegas
11
- VERSION = "0.1.8"
12
+ VERSION = "0.1.9"
12
13
  WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i)
14
+ JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i)
13
15
 
14
16
  autoload :Runner, 'vegas/runner'
17
+
15
18
  end
@@ -17,7 +17,7 @@ module Vegas
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
- ROOT_DIR = File.expand_path(File.join('~', '.vegas'))
20
+ ROOT_DIR = ENV['HOME'] ? File.expand_path(File.join('~', '.vegas')) : nil
21
21
  PORT = 5678
22
22
  HOST = WINDOWS ? 'localhost' : '0.0.0.0'
23
23
 
@@ -78,6 +78,9 @@ module Vegas
78
78
  end
79
79
 
80
80
  def app_dir
81
+ if !options[:app_dir] && !ROOT_DIR
82
+ raise ArgumentError.new("nor --app-dir neither EVN['HOME'] defined")
83
+ end
81
84
  options[:app_dir] || File.join(ROOT_DIR, filesystem_friendly_app_name)
82
85
  end
83
86
 
@@ -99,6 +102,7 @@ module Vegas
99
102
 
100
103
  def start(path = nil)
101
104
  logger.info "Running with Windows Settings" if WINDOWS
105
+ logger.info "Running with JRuby" if JRUBY
102
106
  logger.info "Starting #{quoted_app_name}..."
103
107
  begin
104
108
  check_for_running(path)
@@ -168,25 +172,37 @@ module Vegas
168
172
  logger.info "Running with Rack handler: #{@rack_handler.inspect}"
169
173
 
170
174
  rack_handler.run app, :Host => host, :Port => port do |server|
171
- trap(kill_command) do
172
- ## Use thins' hard #stop! if available, otherwise just #stop
173
- server.respond_to?(:stop!) ? server.stop! : server.stop
174
- logger.info "#{quoted_app_name} received INT ... stopping"
175
- delete_pid!
175
+ kill_commands.each do |command|
176
+ trap(command) do
177
+ ## Use thins' hard #stop! if available, otherwise just #stop
178
+ server.respond_to?(:stop!) ? server.stop! : server.stop
179
+ logger.info "#{quoted_app_name} received INT ... stopping"
180
+ delete_pid!
181
+ end
176
182
  end
177
183
  end
178
184
  end
179
185
 
180
186
  # Adapted from Rackup
181
187
  def daemonize!
182
- if RUBY_VERSION < "1.9"
188
+ if JRUBY
189
+ # It's not a true daemon but when executed with & works like one
190
+ thread = Thread.new {daemon_execute}
191
+ thread.join
192
+
193
+ elsif RUBY_VERSION < "1.9"
183
194
  logger.debug "Parent Process: #{Process.pid}"
184
195
  exit!(0) if fork
185
196
  logger.debug "Child Process: #{Process.pid}"
197
+ daemon_execute
198
+
186
199
  else
187
200
  Process.daemon(true, true)
201
+ daemon_execute
188
202
  end
189
-
203
+ end
204
+
205
+ def daemon_execute
190
206
  File.umask 0000
191
207
  FileUtils.touch log_file
192
208
  STDIN.reopen log_file
@@ -207,7 +223,7 @@ module Vegas
207
223
 
208
224
  def kill!
209
225
  pid = File.read(pid_file)
210
- logger.warn "Sending INT to #{pid.to_i}"
226
+ logger.warn "Sending #{kill_command} to #{pid.to_i}"
211
227
  Process.kill(kill_command, pid.to_i)
212
228
  rescue => e
213
229
  logger.warn "pid not found at #{pid_file} : #{e}"
@@ -279,7 +295,7 @@ module Vegas
279
295
 
280
296
  # If all else fails, we'll use Thin
281
297
  else
282
- Rack::Handler::Thin
298
+ JRUBY ? Rack::Handler::WEBrick : Rack::Handler::Thin
283
299
  end
284
300
  end
285
301
 
@@ -375,8 +391,8 @@ module Vegas
375
391
  exit
376
392
  end
377
393
 
378
- def kill_command
379
- WINDOWS ? 1 : :INT
394
+ def kill_commands
395
+ WINDOWS ? [1] : [:INT, :TERM]
380
396
  end
381
397
 
382
398
  def delete_pid!
@@ -20,7 +20,9 @@ module TestHelper
20
20
 
21
21
  def vegas(*args, &block)
22
22
  Vegas::Runner.any_instance.stubs(:daemonize!).once
23
- Rack::Handler::Thin.stubs(:run).once
23
+
24
+ Vegas::JRUBY ? Rack::Handler::WEBrick.stubs(:run).once : Rack::Handler::Thin.stubs(:run).once
25
+
24
26
  @vegas = Vegas::Runner.new(*args, &block)
25
27
  end
26
28
 
@@ -1,8 +1,8 @@
1
- require File.join('.', File.dirname(__FILE__), 'test_helper.rb')
1
+ require 'test_helper'
2
2
 
3
3
  Vegas::Runner.class_eval do
4
4
  remove_const :ROOT_DIR
5
- ROOT_DIR = File.join(File.dirname(__FILE__), 'tmp', '.vegas')
5
+ Vegas::Runner::ROOT_DIR = File.join(File.dirname(__FILE__), 'tmp', '.vegas')
6
6
  end
7
7
 
8
8
  describe 'Vegas::Runner' do
@@ -130,8 +130,12 @@ describe 'Vegas::Runner' do
130
130
  vegas(RackApp1, 'rack_app_1', {:skip_launch => true, :sessions => true})
131
131
  end
132
132
 
133
- it "sets default rack handler to thin" do
134
- @vegas.rack_handler.should == Rack::Handler::Thin
133
+ it "sets default rack handler to thin when in ruby and WEBrick when in jruby" do
134
+ if Vegas::JRUBY
135
+ @vegas.rack_handler.should == Rack::Handler::WEBrick
136
+ else
137
+ @vegas.rack_handler.should == Rack::Handler::Thin
138
+ end
135
139
  end
136
140
  end
137
141
 
@@ -157,6 +161,30 @@ describe 'Vegas::Runner' do
157
161
  end
158
162
  end
159
163
 
164
+ describe 'without environment' do
165
+
166
+ Vegas::Runner::ROOT_DIR = nil
167
+
168
+ before do
169
+ @app_dir = './test/tmp'
170
+ end
171
+
172
+ it 'should be ok with --app-dir' do
173
+ vegas(RackApp1, 'rack_app_1', {:skip_launch => true, :app_dir => @app_dir})
174
+ @vegas.app_dir.should == @app_dir
175
+ end
176
+
177
+ it 'should raise an exception without --app-dir' do
178
+ success = false
179
+ begin
180
+ vegas(RackApp1, 'rack_app_1', {:skip_launch => true})
181
+ rescue ArgumentError
182
+ success = true
183
+ end
184
+ success.should == true
185
+ end
186
+
187
+ end
160
188
 
161
189
  end
162
190
 
@@ -1,52 +1,43 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{vegas}
8
- s.version = "0.1.8"
7
+ s.name = "vegas"
8
+ s.version = "0.1.9"
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-10-11}
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.}
12
+ s.date = "2009-08-30"
13
+ s.description = "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 = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
- ".gitignore",
21
- "History.txt",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "lib/vegas.rb",
26
- "lib/vegas/runner.rb",
27
- "test/apps.rb",
28
- "test/test_app/bin/test_app",
29
- "test/test_app/bin/test_rack_app",
30
- "test/test_app/test_app.rb",
31
- "test/test_helper.rb",
32
- "test/test_vegas_runner.rb",
33
- "vegas.gemspec"
34
- ]
35
- s.homepage = %q{http://code.quirkey.com/vegas}
36
- s.rdoc_options = ["--charset=UTF-8"]
37
- s.require_paths = ["lib"]
38
- s.rubyforge_project = %q{quirkey}
39
- s.rubygems_version = %q{1.3.7}
40
- s.summary = %q{Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps.}
41
- s.test_files = [
20
+ "History.txt",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "lib/vegas.rb",
25
+ "lib/vegas/runner.rb",
42
26
  "test/apps.rb",
43
- "test/test_app/test_app.rb",
44
- "test/test_helper.rb",
45
- "test/test_vegas_runner.rb"
27
+ "test/test_app/bin/test_app",
28
+ "test/test_app/bin/test_rack_app",
29
+ "test/test_app/test_app.rb",
30
+ "test/test_helper.rb",
31
+ "test/test_vegas_runner.rb",
32
+ "vegas.gemspec"
46
33
  ]
34
+ s.homepage = "http://code.quirkey.com/vegas"
35
+ s.require_paths = ["lib"]
36
+ s.rubyforge_project = "quirkey"
37
+ s.rubygems_version = "1.8.10"
38
+ s.summary = "Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps."
47
39
 
48
40
  if s.respond_to? :specification_version then
49
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
41
  s.specification_version = 3
51
42
 
52
43
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
metadata CHANGED
@@ -1,94 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: vegas
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 8
9
- version: 0.1.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.9
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Aaron Quint
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-10-11 00:00:00 -07:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2009-08-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rack
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70197311115560 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 0
31
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
32
21
  version: 1.0.0
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: mocha
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70197311115560
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ requirement: &70197311114760 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
29
+ requirements:
41
30
  - - ~>
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 9
46
- - 8
31
+ - !ruby/object:Gem::Version
47
32
  version: 0.9.8
48
33
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: bacon
52
34
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70197311114760
36
+ - !ruby/object:Gem::Dependency
37
+ name: bacon
38
+ requirement: &70197311113980 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
40
+ requirements:
56
41
  - - ~>
57
- - !ruby/object:Gem::Version
58
- segments:
59
- - 1
60
- - 1
61
- - 0
42
+ - !ruby/object:Gem::Version
62
43
  version: 1.1.0
63
44
  type: :development
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: sinatra
67
45
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70197311113980
47
+ - !ruby/object:Gem::Dependency
48
+ name: sinatra
49
+ requirement: &70197311112980 !ruby/object:Gem::Requirement
69
50
  none: false
70
- requirements:
51
+ requirements:
71
52
  - - ~>
72
- - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
- - 9
76
- - 4
53
+ - !ruby/object:Gem::Version
77
54
  version: 0.9.4
78
55
  type: :development
79
- version_requirements: *id004
80
- description: 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.
81
- email:
56
+ prerelease: false
57
+ version_requirements: *70197311112980
58
+ description: Vegas aims to solve the simple problem of creating executable versions
59
+ of Sinatra/Rack apps. It includes a class Vegas::Runner that wraps Rack/Sinatra
60
+ applications and provides a simple command line interface and launching mechanism.
61
+ email:
82
62
  - aaron@quirkey.com
83
63
  executables: []
84
-
85
64
  extensions: []
86
-
87
- extra_rdoc_files:
65
+ extra_rdoc_files:
88
66
  - LICENSE
89
67
  - README.rdoc
90
- files:
91
- - .gitignore
68
+ files:
92
69
  - History.txt
93
70
  - LICENSE
94
71
  - README.rdoc
@@ -102,40 +79,29 @@ files:
102
79
  - test/test_helper.rb
103
80
  - test/test_vegas_runner.rb
104
81
  - vegas.gemspec
105
- has_rdoc: true
106
82
  homepage: http://code.quirkey.com/vegas
107
83
  licenses: []
108
-
109
84
  post_install_message:
110
- rdoc_options:
111
- - --charset=UTF-8
112
- require_paths:
85
+ rdoc_options: []
86
+ require_paths:
113
87
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
88
+ required_ruby_version: !ruby/object:Gem::Requirement
115
89
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- segments:
120
- - 0
121
- version: "0"
122
- required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
95
  none: false
124
- requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- segments:
128
- - 0
129
- version: "0"
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
130
100
  requirements: []
131
-
132
101
  rubyforge_project: quirkey
133
- rubygems_version: 1.3.7
102
+ rubygems_version: 1.8.10
134
103
  signing_key:
135
104
  specification_version: 3
136
- summary: Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps.
137
- test_files:
138
- - test/apps.rb
139
- - test/test_app/test_app.rb
140
- - test/test_helper.rb
141
- - test/test_vegas_runner.rb
105
+ summary: Vegas aims to solve the simple problem of creating executable versions of
106
+ Sinatra/Rack apps.
107
+ test_files: []
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- .DS_Store
2
- test/tmp
3
- pkg/*
4
- _layouts
5
- *.sw?