picnic 0.6.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ === 0.7 :: In progress...
2
+
3
+ * Can now configure the CLI aspect of an app to respond to additional command-
4
+ line flags. This is done by passing a block of OptionParser calls as
5
+ an :extra_cli_options parameter to the Cli initializer.
6
+ * activerecord is no longer a requirement. However you should make sure that
7
+ you take care of loading activerecord in your app if you intend to use
8
+ Camping's database functionality.
9
+
1
10
  === 0.6.5 :: 2008-09-18
2
11
 
3
12
  * Fixed compatibility with ActiveSupport 2.1.
data/Rakefile CHANGED
@@ -57,6 +57,6 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
57
57
  # note that camping-1.5.0.180 is now bundled with picnic in the vendor directory.
58
58
  p.extra_deps = [
59
59
  'markaby',
60
- ['activesupport', '>=2.0.2']
60
+ 'activesupport'
61
61
  ]
62
62
  end
data/lib/picnic/cli.rb CHANGED
@@ -1,12 +1,5 @@
1
1
  require 'optparse'
2
2
 
3
- begin
4
- require 'active_support'
5
- rescue LoadError
6
- require 'rubygems'
7
- require 'active_support'
8
- end
9
-
10
3
  module Picnic
11
4
  # Provides a command-line interface for your app.
12
5
  # This is useful for creating a 'bin' file for launching your application.
@@ -22,7 +15,7 @@ module Picnic
22
15
  #
23
16
  # cli = Picnic::Cli.new(
24
17
  # 'foo',
25
- # :app_path => File.expand_path(File.dirname(File.expand_path(__FILE__)))
18
+ # :app_path => "/path/to/foo.br"
26
19
  # )
27
20
  #
28
21
  # cli.handle_cli_input
@@ -38,7 +31,7 @@ module Picnic
38
31
  # binary, which by default is expected to be in the same directory
39
32
  # as the service control script.
40
33
  # +options+:: A hash overriding default options. The options are:
41
- # +app_path+:: The path to your application's main Ruby file.
34
+ # +app_file+:: The path to your application's main Ruby file.
42
35
  # By default this is expected to be <tt>../lib/<app>.rb</tt>
43
36
  # +pid_file+:: Where the app's PID file (containing the app's
44
37
  # process ID) should be placed. By default this is
@@ -49,28 +42,33 @@ module Picnic
49
42
  @app = app
50
43
 
51
44
  @options = options || {}
52
- @options[:app_path] ||= File.expand_path(File.dirname(File.expand_path(__FILE__))+"/../lib/#{app}.rb")
45
+ @options[:app_file] ||= File.expand_path(File.dirname(File.expand_path($0))+"/../lib/#{app}.rb")
53
46
  @options[:app_module] ||= app.capitalize
54
47
  @options[:pid_file] ||= "/etc/#{app}/#{app}.pid"
55
48
  @options[:conf_file] ||= nil
56
49
  @options[:verbose] ||= false
57
-
58
- @options = options
59
50
  end
60
51
 
61
52
  # Parses command line options given to the script.
62
53
  def handle_cli_input
63
- if File.exists? options[:app_path]
54
+ if File.exists? options[:app_file]
64
55
  # try to use given app base path
65
- $: << File.dirname(options[:app_path])
66
- path = File.dirname(options[:app_path])+"/"
56
+ $APP_PATH = File.dirname(options[:app_file]).gsub(/\/lib\/?$/, '')
67
57
  else
68
- # fall back to using gem installation
69
- path = ""
70
58
  require 'rubygems'
59
+
60
+ # fall back to using gem installation
61
+ matches = Gem::source_index.find_name(app)
62
+ raise LoadError, "#{app} gem doesn't appear to be installed!" if matches.empty?
63
+
64
+ gem_spec = matches.last
65
+ $APP_PATH = gem_spec.full_gem_path
66
+
71
67
  gem(app)
72
68
  end
73
69
 
70
+ $: << $APP_PATH+"/lib"
71
+
74
72
  $PID_FILE = "/etc/#{app}/#{app}.pid"
75
73
 
76
74
  OptionParser.new do |opts|
@@ -97,23 +95,26 @@ module Picnic
97
95
  puts "Not running as daemon. Ignoring pid option"
98
96
  end
99
97
  end
100
-
98
+
99
+ # :extra_cli_options should be a block with additonal app-specific opts.on() calls
100
+ if @options[:extra_cli_options]
101
+ @options[:extra_cli_options].call(opts)
102
+ end
103
+
101
104
  opts.on_tail("-h", "--help", "Show this message") do
102
105
  puts opts
103
106
  exit
104
107
  end
105
108
 
106
109
  opts.on_tail("-V", "--version", "Show version number") do
107
- require "#{path}/lib/#{app}/version"
108
- app_mod = @options[:app_module].constantize
110
+ require "#{$APP_PATH}/lib/#{app}/version.rb"
111
+ app_mod = Object.const_get(@options[:app_module])
109
112
  puts "#{app}-#{app_mod::VERSION::STRING}"
110
113
  exit
111
114
  end
112
115
  end.parse!
113
116
 
114
- $APP_PATH = options[:app_path]
115
-
116
- load "#{path}/lib/#{app}.rb"
117
+ require "#{$APP_PATH}/lib/#{app}.rb"
117
118
  end
118
119
  end
119
120
  end
@@ -169,58 +169,67 @@ module Picnic
169
169
  :cwd => $APP_PATH
170
170
  }
171
171
 
172
- # need to close all IOs before daemonizing
173
- $LOG.close if $DAEMONIZE
174
-
175
- public_dirs = Picnic::Conf.public_dirs || Picnic::Conf.public_dir
176
- public_dirs = [public_dirs] unless
177
- public_dirs.kind_of? Array || public_dirs.nil?
178
-
179
172
  begin
180
- app_mod = self
181
- mongrel = Mongrel::Configurator.new settings do
182
- daemonize :log_file => Picnic::Conf.log[:file], :cwd => $APP_PATH if $DAEMONIZE
183
- app_mod.init_logger
184
- #app_mod.init_db_logger
185
- listener :port => Picnic::Conf.port do
186
- uri Picnic::Conf.uri_path, :handler => Mongrel::Camping::CampingHandler.new(app_mod)
187
-
188
- if public_dirs
189
- public_dirs.each do |d|
190
- dir = d[:dir]
191
- path = "#{Picnic::Conf.uri_path}/#{d[:path]}".gsub(/\/\/+/,'/')
192
- $LOG.debug("Mounting public directory #{dir.inspect} to path #{path.inspect}.")
193
- uri(path, :handler => Mongrel::DirHandler.new(dir))
173
+ # need to close all IOs before daemonizing
174
+ $LOG.close if $DAEMONIZE
175
+
176
+ public_dirs = Picnic::Conf.public_dirs || Picnic::Conf.public_dir
177
+ public_dirs = [public_dirs] unless
178
+ public_dirs.kind_of? Array || public_dirs.nil?
179
+
180
+ begin
181
+ app_mod = self
182
+ mongrel = Mongrel::Configurator.new settings do
183
+ daemonize :log_file => Picnic::Conf.log[:file], :cwd => $APP_PATH if $DAEMONIZE
184
+ app_mod.init_logger
185
+ #app_mod.init_db_logger
186
+ listener :port => Picnic::Conf.port do
187
+ uri Picnic::Conf.uri_path, :handler => Mongrel::Camping::CampingHandler.new(app_mod)
188
+
189
+ if public_dirs
190
+ public_dirs.each do |d|
191
+ dir = d[:dir]
192
+ path = "#{Picnic::Conf.uri_path}/#{d[:path]}".gsub(/\/\/+/,'/')
193
+ $LOG.debug("Mounting public directory #{dir.inspect} to path #{path.inspect}.")
194
+ uri(path, :handler => Mongrel::DirHandler.new(dir))
195
+ end
194
196
  end
197
+
198
+ setup_signals
195
199
  end
196
-
197
- setup_signals
198
200
  end
199
- end
200
- rescue Errno::EADDRINUSE
201
- exit 1
202
- end
203
-
204
- mongrel.run
205
-
206
-
207
- if $DAEMONIZE && $PID_FILE
208
- write_pid_file
209
- unless File.exists? $PID_FILE
210
- $LOG.error "#{self} could not start because pid file #{$PID_FILE.inspect} could not be created."
201
+ rescue Errno::EADDRINUSE
211
202
  exit 1
212
203
  end
213
- end
214
-
215
- puts "\n** #{self} is running at http://#{ENV['HOSTNAME'] || 'localhost'}:#{Picnic::Conf.port}#{Picnic::Conf.uri_path} and logging to '#{Picnic::Conf.log[:file]}'"
216
204
 
217
205
 
218
- self.prestart if self.respond_to? :prestart
219
- mongrel.join
220
-
221
- clear_pid_file
222
-
223
- puts "\n** #{self} is stopped (#{Time.now})"
206
+ mongrel.run
207
+
208
+ if $DAEMONIZE && $PID_FILE
209
+ write_pid_file
210
+ unless File.exists? $PID_FILE
211
+ $LOG.error "#{self} could not start because pid file #{$PID_FILE.inspect} could not be created."
212
+ exit 1
213
+ end
214
+ end
215
+
216
+ puts "\n** #{self} is running at http://#{ENV['HOSTNAME'] || 'localhost'}:#{Picnic::Conf.port}#{Picnic::Conf.uri_path} and logging to '#{Picnic::Conf.log[:file]}'"
217
+
218
+
219
+ self.prestart if self.respond_to? :prestart
220
+ mongrel.join
221
+
222
+ clear_pid_file
223
+
224
+ if mongrel.needs_restart
225
+ $LOG.info "#{self} is restarting..."
226
+ puts "\n** #{self} is restarting..."
227
+ else
228
+ $LOG.info "#{self} is stopped."
229
+ puts "\n** #{self} is stopped (#{Time.now})"
230
+ end
231
+
232
+ end while mongrel.needs_restart
224
233
  end
225
234
 
226
235
  # Theoretically this should launch your Picnic app as a FastCGI process.
@@ -247,6 +247,11 @@ module Picnic
247
247
  end
248
248
 
249
249
  def get_state
250
+ # FIXME: This is a poor attempt at trying to fix a problem where occassionally
251
+ # an empty pid_file is read, probably because it has not yet been
252
+ # fully written.
253
+ sleep 0.5
254
+
250
255
  if File.exists? @options[:pid_file]
251
256
  pid = File.read(@options[:pid_file]).strip
252
257
 
@@ -1,8 +1,8 @@
1
1
  module Picnic #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 6
5
- TINY = 5
4
+ MINOR = 7
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/picnic.rb CHANGED
@@ -1,22 +1,13 @@
1
- $: << File.dirname(File.expand_path(__FILE__))
2
- $: << File.dirname(File.expand_path(__FILE__))+"/../vendor/camping-1.5.180/lib"
1
+ require 'rubygems'
2
+ #require 'active_support'
3
3
 
4
- unless Object.const_defined?(:ActiveSupport)
5
- begin
6
- require 'active_support'
7
- rescue LoadError
8
- require 'rubygems'
9
- gem 'activesupport', '>=2.0.2'
10
- gem 'activerecord', '>=2.0.2'
11
- require 'active_support'
12
- end
13
- end
4
+ $: << File.dirname(File.expand_path(__FILE__))+"/../vendor/camping-1.5.180/lib"
5
+ require "camping"
14
6
 
15
- require 'camping'
16
-
17
- require 'picnic/utils'
18
- require 'picnic/conf'
19
- require 'picnic/postambles'
7
+ $: << File.dirname(File.expand_path(__FILE__))
8
+ require "picnic/utils.rb"
9
+ require "picnic/conf.rb"
10
+ require "picnic/postambles.rb"
20
11
 
21
12
 
22
13
  class Module
@@ -84,7 +75,7 @@ class Module
84
75
  # your app's conf file.
85
76
  #
86
77
  def authenticate_using(mod)
87
- require 'picnic/authentication'
78
+ load "picnic/authentication.rb"
88
79
  mod = self::Authentication.const_get(mod.to_s.camelize) unless mod.kind_of? Module
89
80
 
90
81
  $LOG.info("Enabling authentication for all requests using #{mod.inspect}.")
@@ -98,7 +89,7 @@ class Module
98
89
  # Launches the web server to run your Picnic app.
99
90
  # This method will continue to run as long as your server is running.
100
91
  def start_picnic
101
- require 'picnic/postambles'
92
+ require "#{File.dirname(File.expand_path(__FILE__))}/picnic/postambles.rb"
102
93
  self.extend self::Postambles
103
94
 
104
95
  if $PID_FILE && !(self::Conf.server.to_s == 'mongrel' || self::Conf.server.to_s == 'webrick')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picnic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zukowski
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-26 00:00:00 -04:00
12
+ date: 2008-10-28 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.2
33
+ version: "0"
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: hoe