mongrel2 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,8 +1,21 @@
1
+ 2012-02-10 Michael Granger <ged@FaerieMUD.org>
2
+
3
+ * examples/config.rb, lib/mongrel2/config/dsl.rb:
4
+ Start work on detailed docs for the config DSL
5
+ [fd35a1c88881] [tip]
6
+
1
7
  2012-02-06 Michael Granger <ged@FaerieMUD.org>
2
8
 
9
+ * .rvm.gems, .rvmrc, .tm_properties, bin/m2sh.rb, examples/config.rb,
10
+ lib/mongrel2/config.rb, lib/mongrel2/config/dsl.rb,
11
+ lib/mongrel2/config/server.rb, spec/mongrel2/config/dsl_spec.rb,
12
+ spec/mongrel2/config_spec.rb:
13
+ Make the DSL declarations destructive.
14
+ [8c065a2dcebc]
15
+
3
16
  * .hgtags:
4
17
  Added tag v0.10.0 for changeset 1e9885cbcafd
5
- [d3f06f6344ad] [tip]
18
+ [d3f06f6344ad]
6
19
 
7
20
  * .hgsigs:
8
21
  Added signature for changeset 948877fd6c9d
@@ -29,7 +42,7 @@
29
42
  spec/mongrel2/config/filter_spec.rb,
30
43
  spec/mongrel2/config/route_spec.rb:
31
44
  Updating config database schema/classes for Mongrel 1.8.
32
- [6d2608b23873] [github/master]
45
+ [6d2608b23873]
33
46
 
34
47
  * examples/config.rb:
35
48
  Move the example server back to port 8113
data/DSL.rdoc ADDED
@@ -0,0 +1,300 @@
1
+ = The Mongrel2 Config DSL
2
+
3
+ The Mongrel2::Config::DSL module is a mixin that will add functions to your
4
+ namespace that can create and replace configuration items in the current
5
+ Mongrel2 config database.
6
+
7
+ If you're creating a config that will be run standalone, you'll need to
8
+ point the config classes to the right database before using the DSL:
9
+
10
+ #!/usr/bin/env ruby
11
+
12
+ require 'mongrel2'
13
+ require 'mongrel2/config'
14
+ require 'mongrel2/config/dsl'
15
+
16
+ Mongrel2::Config.configure( configdb: 'myconfig.sqlite' )
17
+ include Mongrel2::Config::DSL
18
+
19
+ server 'myserver' do
20
+ # ...
21
+ end
22
+
23
+ If you're creating a config to be loaded via m2sh.rb, you don't need any of
24
+ that, as m2sh.rb provides its own prelude before loading the config.
25
+
26
+ == DSL Syntax
27
+
28
+ There is basically one directive for each configuration item, and the layout follows the basic structure described in the {Mongrel2 manual}[http://mongrel2.org/static/book-finalch4.html#x6-260003.4].
29
+
30
+
31
+ === server
32
+
33
+ server <uuid> { <server config block> }
34
+
35
+ This creates or replaces the server associated with the specified +uuid+. The
36
+ <tt>server config block</tt> has directives for each of the server attributes,
37
+ each of which corresponds to one of the columns in the configuration database's
38
+ +server+ table (descriptions largely borrowed from the
39
+ manual[http://mongrel2.org/static/book-finalch4.html#x6-270003.4.1]):
40
+
41
+ [chroot +directory+] The directory that Mongrel2 should chroot to at startup.
42
+ Defaults to <tt>/var/www</tt>.
43
+ [access_log +path+] The path to the access log file relative to the +chroot+.
44
+ Usually starts with a ‘/’. Defaults to
45
+ <tt>/logs/access.log</tt>.
46
+ [error_log +path+] The error log file, just like +access_log+. Defaults to
47
+ <tt>/logs/error.log</tt>.
48
+ [pid_file +path+] The path to the PID file, relative to the +chroot+.
49
+ Defaults to <tt>/run/mongrel2.pid</tt>.
50
+ [default_host +name+] Which +host+ in the server to use as the default if
51
+ the +Host+ header doesn't match any host's +matching+
52
+ attribute. Defaults to <tt>localhost</tt>.
53
+ [bind_addr +ipaddr+] The IP address to bind to; default is <tt>0.0.0.0</tt>.
54
+ [port +int+] The port the server should listen on for new connections;
55
+ defaults to <tt>8888</tt>.
56
+
57
+ The server will be saved immediately upon exiting the block, and will return the
58
+ saved Mongrel2::Config::Server object.
59
+
60
+
61
+ === host
62
+
63
+ host <name> { <host config block> }
64
+
65
+ This creates or replaces the named Host within a +server+ block. Inside the
66
+ <tt>host config block</tt>, there are directives for further configuring the
67
+ Host, adding Routes, and setting up Handler, Proxy, and Directory targets
68
+ for Routes.
69
+
70
+ [matching +pattern+] This is a pattern that’s used to match incoming
71
+ <tt>Host</tt> headers for routing purposes.
72
+ [maintenance +boolean+] This is a (currently unused) setting that will display
73
+ a "down for maintenance" page.
74
+
75
+ The rest of the block will likely be concerned with setting up the routes for
76
+ the host using the +route+, +handler+, +directory+, and +proxy+ directives, e.g.:
77
+
78
+ host 'main' do
79
+ matching 'example.com'
80
+ maintenance false
81
+
82
+ # Hello world application
83
+ route '/hello', handler('tcp://127.0.0.1:9999', 'helloworld-handler')
84
+ # Contact form handler
85
+ route '/contact', handler('tcp://127.0.0.1:9995', 'contact-form')
86
+
87
+ # reverse proxy for a non-mongrel application listening on 8080
88
+ route '/api', proxy('127.0.0.1', 8080)
89
+ end
90
+ # => #<Mongrel2::Config::Host ...>
91
+
92
+ Since the block is just a Ruby block, and each directive returns the configured
93
+ object, you can use conditionals, assign targets to variables to be reused later,
94
+ etc:
95
+
96
+ require 'socket'
97
+
98
+ host 'test' do
99
+ matching 'testing.example.com'
100
+
101
+ # Decide which address to listen to, and which app to use based on which
102
+ # host the config is running on.
103
+ testhandler =
104
+ if Socket.gethostname.include?( 'example.com' )
105
+ handler 'tcp://0.0.0.0:31218', 'ci-builder'
106
+ else
107
+ handler 'tcp://127.0.0.1', 'unittest-builder'
108
+ end
109
+
110
+ route '', testhandler
111
+ end
112
+
113
+ === route
114
+
115
+ route <pattern>, <target>, [<opts>]
116
+
117
+ Create a route in the current host that will match the given +pattern+ and
118
+ pass the request to the specified +target+, which should be a Handler, a
119
+ Directory, or a Proxy.
120
+
121
+ The only current option is +reversed+, which (if +true+) means that the pattern
122
+ is bound to the end rather than the beginning of the path.
123
+
124
+ It returns the configured Route object.
125
+
126
+ route '/demo', handler('tcp://localhost:9400', 'demo-handler')
127
+ # => #<Mongrel2::Config::Route ...>
128
+ route '.css', directory('/public/css', 'base.css', 'text/css'), reverse: true
129
+
130
+ # Use the same image-factory handler for each image type
131
+ image_handler = handler('tcp://localhost:9300', 'image-factory')
132
+ route '.jpg', image_handler, reverse: true
133
+ route '.gif', image_handler, reverse: true
134
+ route '.png', image_handler, reverse: true
135
+ route '.ico', image_handler, reverse: true
136
+
137
+ === handler
138
+
139
+ handler <send_spec>, <send_ident>, [<recv_spec>[, <recv_ident>]], [<options>]
140
+
141
+ Create a Handler that will send and receive on +send_spec+ and +recv_spec+ 0mq
142
+ sockets, respectively. The application's +send_ident+ is an identifier (usually
143
+ a UUID) that will be used to register the send socket so messages persist
144
+ through crashes.
145
+
146
+ If no +recv_spec+ is given, the port immediately below the +send_spec+ is used.
147
+
148
+ The +recv_ident+ is another UUID if you want the receive socket to subscribe to
149
+ its messages. Handlers properly mention the send_ident on all returned
150
+ messages, so you should either set this to nothing and don’t subscribe, or set
151
+ it to the same as +send_ident+.
152
+
153
+ Valid +options+ for Handlers are:
154
+
155
+ [raw_payload +boolean+] ?
156
+ [protocol +name+] The protocol used to communicate with the handler. Should
157
+ be either 'tnetstring' or 'json' (the default).
158
+
159
+ As with the other directives, +handler+ returns the newly-saved Handler object.
160
+ This means that you can either assign it to a variable for later inclusion in
161
+ one or more Route declarations, or you can define it in the <tt>route</tt> itself:
162
+
163
+ route '/gravatar/:email', handler('tcp://localhost:1480', 'gravatar-service')
164
+ # => #<Mongrel2::Config::Route ...>
165
+
166
+ See the documentation for @route@ for more examples of this.
167
+
168
+
169
+ === directory
170
+
171
+ directory <base>, [<index_file>[, <default_ctype>[, <options>]]]
172
+
173
+ Create a Dir target for a route that will serve static content from the
174
+ specified +base+ directory. Returns the saved Dir object.
175
+
176
+ There aren't currently any supported +options+, but the Mongrel2 manual
177
+ says that "eventually you’ll be able to tweak more and more of the
178
+ settings to control how Dirs work."
179
+
180
+
181
+ === proxy
182
+
183
+ proxy <addr>[, <port>]
184
+
185
+ Create a Proxy target for a route that will proxy another server listening
186
+ on the given +addr+ and +port+. If not specified, +port+ defaults to
187
+ <tt>80</tt>. Returns the saved Proxy object.
188
+
189
+
190
+ === filter
191
+
192
+ filter <path>[, <settings>]
193
+
194
+ Set up a Filter[http://mongrel2.org/static/book-finalch6.html#x8-840005.8]
195
+ for the containing Server by loading the object from the specified +path+
196
+ and passing it the specified +options+ as a
197
+ TNetstring[http://tnetstrings.org/].
198
+
199
+
200
+ === setting/settings
201
+
202
+ setting <name>, <value>
203
+ settings <name1> => <value1>[, <name2> => <value2>, ...]
204
+
205
+ Set one or more of Mongrel2's internal settings. See the
206
+ {tweakable expert settings section}[http://mongrel2.org/static/book-finalch4.html#x6-410003.10]
207
+ of the manual for valid values and more details on what these do.
208
+
209
+ An example (from the manual):
210
+
211
+ settings "zeromq.threads" => 1,
212
+ "upload.temp_store" => "/home/zedshaw/projects/mongrel2/tmp/upload.XXXXXX",
213
+ "upload.temp_store_mode" => "0666"
214
+ # => [ #<Mongrel2::Config::Setting ...>, #<Mongrel2::Config::Setting ...>, ... ]
215
+
216
+ === mimetype/mimetypes
217
+
218
+ mimetype <extension>, <mimetype>
219
+ mimetypes <extension1> => <mimetype1>[, <extension2> => <mimetype2>]
220
+
221
+ Map one or more file +extension+s to a +mimetype+.
222
+
223
+ An example:
224
+
225
+ mimetypes '.ttf' => 'application/x-font-truetype',
226
+ '.otf' => 'application/x-font-opentype'
227
+ # => [#<Mongrel2::Config::Mimetype ...>, ... ]
228
+
229
+
230
+ == Example
231
+
232
+ This is the mongrel2.org config re-expressed in the Ruby DSL:
233
+
234
+ # the server to run them all
235
+ server '2f62bd5-9e59-49cd-993c-3b6013c28f05' do
236
+
237
+ access_log "/logs/access.log"
238
+ error_log "/logs/error.log"
239
+ chroot "./"
240
+ pid_file "/run/mongrel2.pid"
241
+ default_host "mongrel2.org"
242
+ name "main"
243
+ port 6767
244
+
245
+ # your main host
246
+ host "mongrel2.org" do
247
+
248
+ # a sample of doing some handlers
249
+ route '@chat', handler(
250
+ 'tcp://127.0.0.1:9999',
251
+ '54c6755b-9628-40a4-9a2d-cc82a816345e',
252
+ 'tcp://127.0.0.1:9998'
253
+ )
254
+
255
+ route '/handlertest', handler(
256
+ 'tcp://127.0.0.1:9997',
257
+ '34f9ceee-cd52-4b7f-b197-88bf2f0ec378',
258
+ 'tcp://127.0.0.1:9996'
259
+ )
260
+
261
+ # a sample proxy route
262
+ web_app_proxy = proxy( '127.0.0.1', 8080 )
263
+
264
+ route '/chat/', web_app_proxy
265
+ route '/', web_app_proxy
266
+
267
+ # here's a sample directory
268
+ test_directory = directory(
269
+ 'tests/',
270
+ :index_file => 'index.html',
271
+ :default_ctype => 'text/plain'
272
+ )
273
+
274
+ route '/tests/', test_directory
275
+ route '/testsmulti/(.*.json)', test_directory
276
+
277
+ chat_demo_dir = directory(
278
+ 'examples/chat/static/',
279
+ :index_file => 'index.html',
280
+ :default_ctype => 'text/plain'
281
+ )
282
+
283
+ route '/chatdemo/', chat_demo_dir
284
+ route '/static/', chat_demo_dir
285
+
286
+ route '/mp3stream', handler(
287
+ 'tcp://127.0.0.1:9995',
288
+ '53f9f1d1-1116-4751-b6ff-4fbe3e43d142',
289
+ 'tcp://127.0.0.1:9994'
290
+ )
291
+ end
292
+
293
+ end
294
+
295
+ settings(
296
+ "zeromq.threads" => 1,
297
+ "upload.temp_store" => "/home/zedshaw/projects/mongrel2/tmp/upload.XXXXXX",
298
+ "upload.temp_store_mode" => "0666"
299
+ )
300
+
data/History.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ == v0.11.0 [2012-02-15] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ - Make the DSL declarations replace existing records.
4
+ - Flesh out the documentation for the DSL
5
+ - Provide convenience methods for resetting an HTTP request's
6
+ Content-type and Content-encoding headers.
7
+
8
+
1
9
  == v0.10.0 [2012-02-06] Michael Granger <ged@FaerieMUD.org>
2
10
 
3
11
  This release includes updates for Mongrel 1.8 and finishes up the m2sh.rb tool.
data/Manifest.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  .autotest
2
2
  .gemtest
3
3
  ChangeLog
4
+ DSL.rdoc
4
5
  History.rdoc
5
6
  Manifest.txt
6
7
  README.rdoc
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Hoe.plugins.delete :rubyforge
20
20
  hoespec = Hoe.spec 'mongrel2' do
21
21
  self.readme_file = 'README.rdoc'
22
22
  self.history_file = 'History.rdoc'
23
- self.extra_rdoc_files << 'README.rdoc' << 'History.rdoc'
23
+ self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
24
24
  self.spec_extras[:rdoc_options] = ['-t', 'Ruby-Mongrel2']
25
25
 
26
26
  self.developer 'Michael Granger', 'ged@FaerieMUD.org'
data/bin/m2sh.rb CHANGED
@@ -293,7 +293,7 @@ class Mongrel2::M2SHCommand
293
293
 
294
294
  header "Loading config from #{configfile}"
295
295
  source = File.read( configfile )
296
- Mongrel2::Config.init_database!
296
+
297
297
  runspace.module_eval( source, configfile, 0 )
298
298
  end
299
299
  help :load, "Overwrite the config database with the values from the speciifed CONFIGFILE."
@@ -406,7 +406,7 @@ class Mongrel2::M2SHCommand
406
406
  def servers_command( * )
407
407
  header 'SERVERS:'
408
408
  Mongrel2::Config.servers.each do |server|
409
- message "%s [%s]: %s" % [
409
+ message "%s [%s]: %s" % [
410
410
  self.prompt.color( server.name, :key ),
411
411
  server.default_host,
412
412
  server.uuid,
data/examples/config.rb CHANGED
@@ -1,52 +1,37 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # The Mongrel config used by the examples.
3
+ # The Mongrel config used by the examples. Load it with:
4
+ #
5
+ # m2sh.rb -c examples.sqlite load examples/config.rb
6
+ #
4
7
 
5
- BEGIN {
6
- require 'pathname'
7
- basedir = Pathname( __FILE__ ).dirname.parent
8
- libdir = basedir + 'lib'
9
-
10
- $LOAD_PATH.unshift( libdir.to_s )
11
- }
12
-
13
- require 'rubygems'
14
- require 'fileutils'
15
- require 'mongrel2'
16
- require 'mongrel2/config'
17
-
18
- include FileUtils::Verbose
19
-
20
- Mongrel2.log.level = Logger::INFO
21
- Mongrel2::Config.configure( :configdb => 'examples.sqlite' )
22
- include Mongrel2::Config::DSL
8
+ # samples server
9
+ server '34D8E57C-3E91-4F24-9BBE-0B53C1827CB4' do
23
10
 
24
- Mongrel2::Config.init_database!
11
+ name 'main'
12
+ default_host 'www.example.com'
25
13
 
26
- # the server to run them all
27
- server '34D8E57C-3E91-4F24-9BBE-0B53C1827CB4' do
14
+ access_log '/logs/access.log'
15
+ error_log '/logs/error.log'
16
+ chroot '/var/mongrel2'
17
+ pid_file '/run/mongrel2.pid'
28
18
 
29
- access_log "/logs/access.log"
30
- error_log "/logs/error.log"
31
- chroot "/var/mongrel2"
32
- pid_file "/run/mongrel2.pid"
33
- default_host "localhost"
34
- name "main"
35
- port 8113
19
+ bind_addr '0.0.0.0'
20
+ port 8113
36
21
 
37
- # your main host
38
- host "localhost" do
22
+ # your main host
23
+ host 'www.example.com' do
39
24
 
40
25
  route '/', directory( 'data/mongrel2/', 'bootstrap.html', 'text/html' )
41
26
  route '/source', directory( 'examples/', 'README.txt', 'text/plain' )
42
27
 
43
28
  # Handlers
44
- route '/hello', handler( 'tcp://127.0.0.1:9999', 'helloworld-handler' )
45
- route '/dump', handler( 'tcp://127.0.0.1:9997', 'request-dumper' )
29
+ route '/hello', handler( 'tcp://127.0.0.1:9999', 'helloworld-handler' )
30
+ route '/dump', handler( 'tcp://127.0.0.1:9997', 'request-dumper' )
46
31
 
47
32
  end
48
33
 
49
- filter "/usr/local/lib/mongrel2/filters/null.so",
34
+ filter '/usr/local/lib/mongrel2/filters/null.so',
50
35
  extensions: ["*.html", "*.txt"],
51
36
  min_size: 1000
52
37
 
@@ -54,6 +39,3 @@ end
54
39
 
55
40
  setting "zeromq.threads", 1
56
41
 
57
- mkdir_p 'run'
58
- mkdir_p 'logs'
59
-
data/lib/mongrel2.rb CHANGED
@@ -14,10 +14,10 @@ module Mongrel2
14
14
  abort "\n\n>>> Mongrel2 requires Ruby 1.9.2 or later. <<<\n\n" if RUBY_VERSION < '1.9.2'
15
15
 
16
16
  # Library version constant
17
- VERSION = '0.10.0'
17
+ VERSION = '0.11.0'
18
18
 
19
19
  # Version-control revision constant
20
- REVISION = %q$Revision: b3ed6f931afa $
20
+ REVISION = %q$Revision: 5d438ea6037a $
21
21
 
22
22
 
23
23
  require 'mongrel2/logging'
@@ -146,7 +146,7 @@ module Mongrel2
146
146
 
147
147
  return setting_hash
148
148
  end
149
-
149
+
150
150
 
151
151
  ### Return the contents of the configuration schema SQL file.
152
152
  def self::load_config_schema
@@ -3,79 +3,7 @@
3
3
  require 'mongrel2' unless defined?( Mongrel2 )
4
4
  require 'mongrel2/config' unless defined?( Mongrel2::Config )
5
5
 
6
- # Mongrel2 configuration DSL mixin
7
- #
8
- # == Example
9
- #
10
- # This is the mongrel2.org config re-expressed in the Ruby DSL:
11
- #
12
- # # the server to run them all
13
- # server '2f62bd5-9e59-49cd-993c-3b6013c28f05' do
14
- #
15
- # access_log "/logs/access.log"
16
- # error_log "/logs/error.log"
17
- # chroot "./"
18
- # pid_file "/run/mongrel2.pid"
19
- # default_host "mongrel2.org"
20
- # name "main"
21
- # port 6767
22
- #
23
- # # your main host
24
- # host "mongrel2.org" do
25
- #
26
- # # a sample of doing some handlers
27
- # route '@chat', handler(
28
- # 'tcp://127.0.0.1:9999',
29
- # '54c6755b-9628-40a4-9a2d-cc82a816345e',
30
- # 'tcp://127.0.0.1:9998'
31
- # )
32
- #
33
- # route '/handlertest', handler(
34
- # 'tcp://127.0.0.1:9997',
35
- # '34f9ceee-cd52-4b7f-b197-88bf2f0ec378',
36
- # 'tcp://127.0.0.1:9996'
37
- # )
38
- #
39
- # # a sample proxy route
40
- # web_app_proxy = proxy( '127.0.0.1', 8080 )
41
- #
42
- # route '/chat/', web_app_proxy
43
- # route '/', web_app_proxy
44
- #
45
- # # here's a sample directory
46
- # test_directory = directory(
47
- # 'tests/',
48
- # :index_file => 'index.html',
49
- # :default_ctype => 'text/plain'
50
- # )
51
- #
52
- # route '/tests/', test_directory
53
- # route '/testsmulti/(.*.json)', test_directory
54
- #
55
- # chat_demo_dir = directory(
56
- # 'examples/chat/static/',
57
- # :index_file => 'index.html',
58
- # :default_ctype => 'text/plain'
59
- # )
60
- #
61
- # route '/chatdemo/', chat_demo_dir
62
- # route '/static/', chat_demo_dir
63
- #
64
- # route '/mp3stream', handler(
65
- # 'tcp://127.0.0.1:9995',
66
- # '53f9f1d1-1116-4751-b6ff-4fbe3e43d142',
67
- # 'tcp://127.0.0.1:9994'
68
- # )
69
- # end
70
- #
71
- # end
72
- #
73
- # settings(
74
- # "zeromq.threads" => 1,
75
- # "upload.temp_store" => "/home/zedshaw/projects/mongrel2/tmp/upload.XXXXXX",
76
- # "upload.temp_store_mode" => "0666"
77
- # )
78
- #
6
+ # See DSL.rdoc for details on how to use this mixin.
79
7
  module Mongrel2::Config::DSL
80
8
 
81
9
 
@@ -85,10 +13,19 @@ module Mongrel2::Config::DSL
85
13
  class Adapter
86
14
  include Mongrel2::Loggable
87
15
 
88
- ### Adapt the specified +target+ to use a declarative interface.
16
+ ### Create an instance of the specified +targetclass+ using the specified +opts+
17
+ ### as initial values. The first pair of +opts+ will be used in the filter to
18
+ ### find any previous instance and delete it.
89
19
  def initialize( targetclass, opts={} )
90
20
  self.log.debug "Wrapping a %p" % [ targetclass ]
91
21
  @targetclass = targetclass
22
+
23
+ # Use the first pair as the primary key
24
+ unless opts.empty?
25
+ first_pair = Hash[ *opts.first ]
26
+ @targetclass.filter( first_pair ).destroy
27
+ end
28
+
92
29
  @target = @targetclass.new( opts )
93
30
  self.decorate_with_column_declaratives( @target )
94
31
  self.decorate_with_custom_declaratives( @targetclass )
@@ -147,11 +84,32 @@ module Mongrel2::Config::DSL
147
84
  ### Create a Mongrel2::Config::Server with the specified +uuid+, evaluate
148
85
  ### the block (if given) within its context, and return it.
149
86
  def server( uuid, &block )
150
- Mongrel2::Config.init_database
87
+ adapter = nil
88
+
89
+ Mongrel2.log.info "Entering transaction for server %p" % [ uuid ]
90
+ Mongrel2::Config.db.transaction do
91
+ Mongrel2.log.info " ensuring db is set up..."
92
+ Mongrel2::Config.init_database
93
+
94
+ # Set up the options hash with the UUID and reasonable defaults
95
+ # for everything else
96
+ server_opts = {
97
+ uuid: uuid,
98
+ access_log: "/logs/access.log",
99
+ error_log: "/logs/error.log",
100
+ pid_file: "/run/mongrel2.pid",
101
+ default_host: "localhost",
102
+ port: 8888,
103
+ }
104
+
105
+ Mongrel2.log.debug "Server [%s] (block: %p)" % [ uuid, block ]
106
+ adapter = Adapter.new( Mongrel2::Config::Server, server_opts )
107
+ adapter.instance_eval( &block ) if block
108
+
109
+ Mongrel2.log.info " saving server %p..." % [ uuid ]
110
+ adapter.target.save
111
+ end
151
112
 
152
- Mongrel2.log.debug "Server [%s] (block: %p)" % [ uuid, block ]
153
- adapter = Adapter.new( Mongrel2::Config::Server, :uuid => uuid )
154
- adapter.instance_eval( &block ) if block
155
113
  return adapter.target
156
114
  end
157
115
 
@@ -159,7 +117,9 @@ module Mongrel2::Config::DSL
159
117
  ### Set the value of one of the 'Tweakable Expert Settings'
160
118
  def setting( key, val )
161
119
  Mongrel2::Config.init_database
162
- return Mongrel2::Config::Setting.create( :key => key, :value => val )
120
+ setting = Mongrel2::Config::Setting.find_or_create( key: key )
121
+ setting.value = val
122
+ setting.save
163
123
  end
164
124
 
165
125
 
@@ -181,7 +141,7 @@ module Mongrel2::Config::DSL
181
141
  def mimetype( extension, mimetype )
182
142
  Mongrel2::Config.init_database
183
143
 
184
- type = Mongrel2::Config::Mimetype.find_or_create( :extension => extension )
144
+ type = Mongrel2::Config::Mimetype.find_or_create( extension: extension )
185
145
  type.mimetype = mimetype
186
146
  type.save
187
147
 
@@ -90,12 +90,13 @@ class Mongrel2::Config::Server < Mongrel2::Config( :server )
90
90
  self.target.save( :validate => false )
91
91
 
92
92
  Mongrel2.log.debug "Host [%s] (block: %p)" % [ name, block ]
93
- adapter = Mongrel2::Config::DSL::Adapter.new( Mongrel2::Config::Host,
94
- :name => name, :matching => name )
93
+ adapter = Mongrel2::Config::DSL::Adapter.new( Mongrel2::Config::Host, name: name )
94
+ adapter.target.matching = name
95
95
  adapter.instance_eval( &block ) if block
96
96
  self.target.add_host( adapter.target )
97
97
  end
98
98
 
99
+
99
100
  ### Add a Mongrel2::Config::Filter to the Server object with the specified
100
101
  ### +path+ (name) and +settings+ hash.
101
102
  def filter( path, settings={} )
@@ -60,12 +60,24 @@ class Mongrel2::HTTPRequest < Mongrel2::Request
60
60
  end
61
61
 
62
62
 
63
+ ### Set the current request's Content-Type.
64
+ def content_type=( type )
65
+ return self.headers.content_type = type
66
+ end
67
+
68
+
63
69
  ### Fetch the encoding type of the request's content, as set in its header.
64
70
  def content_encoding
65
71
  return self.headers.content_encoding
66
72
  end
67
73
 
68
74
 
75
+ ### Set the request's encoding type.
76
+ def content_encoding=( type )
77
+ return self.headers.content_encoding = type
78
+ end
79
+
80
+
69
81
 
70
82
  #########
71
83
  protected
@@ -31,6 +31,13 @@ describe Mongrel2::Config::DSL do
31
31
  setup_config_db()
32
32
  end
33
33
 
34
+ before( :each ) do
35
+ Mongrel2::Config::Server.truncate
36
+ Mongrel2::Config::Host.truncate
37
+ Mongrel2::Config::Route.truncate
38
+ Mongrel2::Config::Filter.truncate
39
+ end
40
+
34
41
  after( :all ) do
35
42
  reset_logging()
36
43
  end
@@ -161,6 +168,14 @@ describe Mongrel2::Config::DSL do
161
168
 
162
169
  describe 'settings' do
163
170
 
171
+ before( :all ) do
172
+ @ids = Mongrel2::Config::Setting.map( :id )
173
+ end
174
+
175
+ after( :each ) do
176
+ Mongrel2::Config::Setting.dataset.filter( ~:id => @ids ).delete
177
+ end
178
+
164
179
  it "can set the expert tweakable settings en masse" do
165
180
  result = settings(
166
181
  "zeromq.threads" => 8,
@@ -54,7 +54,8 @@ describe Mongrel2::Config do
54
54
 
55
55
  it "has a convenience method for fetching an Array of all of its configured servers" do
56
56
  Mongrel2::Config.init_database
57
- Mongrel2::Config::Server.dataset.truncate
57
+ Mongrel2::Config::Server.truncate
58
+
58
59
  s = Mongrel2::Config::Server.create(
59
60
  uuid: TEST_UUID,
60
61
  access_log: '/log/access.log',
@@ -97,10 +97,20 @@ describe Mongrel2::HTTPRequest do
97
97
  @req.content_type.should == 'application/x-pdf'
98
98
  end
99
99
 
100
+ it "provides a convenience method for resetting the 'Content-type' header" do
101
+ @req.content_type = 'application/json'
102
+ @req.content_type.should == 'application/json'
103
+ end
104
+
100
105
  it "provides a convenience method for fetching the 'Content-encoding' header" do
101
106
  @req.content_encoding.should == 'gzip'
102
107
  end
103
108
 
109
+ it "provides a convenience method for resetting the 'Content-encoding' header" do
110
+ @req.content_encoding = 'identity'
111
+ @req.content_encoding.should == 'identity'
112
+ end
113
+
104
114
  end
105
115
 
106
116
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongrel2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -48,11 +48,11 @@ cert_chain:
48
48
  -----END CERTIFICATE-----
49
49
 
50
50
  '
51
- date: 2012-02-06 00:00:00.000000000 Z
51
+ date: 2012-02-16 00:00:00.000000000 Z
52
52
  dependencies:
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: nokogiri
55
- requirement: &70339771539100 !ruby/object:Gem::Requirement
55
+ requirement: &70337700771620 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ~>
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: '1.5'
61
61
  type: :runtime
62
62
  prerelease: false
63
- version_requirements: *70339771539100
63
+ version_requirements: *70337700771620
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: sequel
66
- requirement: &70339771538660 !ruby/object:Gem::Requirement
66
+ requirement: &70337700771160 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ~>
@@ -71,10 +71,10 @@ dependencies:
71
71
  version: '3.31'
72
72
  type: :runtime
73
73
  prerelease: false
74
- version_requirements: *70339771538660
74
+ version_requirements: *70337700771160
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: amalgalite
77
- requirement: &70339771538220 !ruby/object:Gem::Requirement
77
+ requirement: &70337700770600 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
80
  - - ~>
@@ -82,10 +82,10 @@ dependencies:
82
82
  version: '1.1'
83
83
  type: :runtime
84
84
  prerelease: false
85
- version_requirements: *70339771538220
85
+ version_requirements: *70337700770600
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: tnetstring
88
- requirement: &70339771537780 !ruby/object:Gem::Requirement
88
+ requirement: &70337700770060 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ~>
@@ -93,10 +93,10 @@ dependencies:
93
93
  version: '0.3'
94
94
  type: :runtime
95
95
  prerelease: false
96
- version_requirements: *70339771537780
96
+ version_requirements: *70337700770060
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: yajl-ruby
99
- requirement: &70339771537340 !ruby/object:Gem::Requirement
99
+ requirement: &70337700769520 !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
102
102
  - - ~>
@@ -104,10 +104,10 @@ dependencies:
104
104
  version: '1.0'
105
105
  type: :runtime
106
106
  prerelease: false
107
- version_requirements: *70339771537340
107
+ version_requirements: *70337700769520
108
108
  - !ruby/object:Gem::Dependency
109
109
  name: trollop
110
- requirement: &70339771536880 !ruby/object:Gem::Requirement
110
+ requirement: &70337700769020 !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
113
113
  - - ~>
@@ -115,10 +115,10 @@ dependencies:
115
115
  version: '1.16'
116
116
  type: :runtime
117
117
  prerelease: false
118
- version_requirements: *70339771536880
118
+ version_requirements: *70337700769020
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: sysexits
121
- requirement: &70339771536400 !ruby/object:Gem::Requirement
121
+ requirement: &70337700768500 !ruby/object:Gem::Requirement
122
122
  none: false
123
123
  requirements:
124
124
  - - ~>
@@ -126,10 +126,10 @@ dependencies:
126
126
  version: '1.0'
127
127
  type: :runtime
128
128
  prerelease: false
129
- version_requirements: *70339771536400
129
+ version_requirements: *70337700768500
130
130
  - !ruby/object:Gem::Dependency
131
131
  name: zmq
132
- requirement: &70339771535960 !ruby/object:Gem::Requirement
132
+ requirement: &70337700767980 !ruby/object:Gem::Requirement
133
133
  none: false
134
134
  requirements:
135
135
  - - ~>
@@ -137,10 +137,10 @@ dependencies:
137
137
  version: 2.1.4
138
138
  type: :runtime
139
139
  prerelease: false
140
- version_requirements: *70339771535960
140
+ version_requirements: *70337700767980
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: hoe-mercurial
143
- requirement: &70339771535500 !ruby/object:Gem::Requirement
143
+ requirement: &70337700767500 !ruby/object:Gem::Requirement
144
144
  none: false
145
145
  requirements:
146
146
  - - ~>
@@ -148,10 +148,10 @@ dependencies:
148
148
  version: 1.3.1
149
149
  type: :development
150
150
  prerelease: false
151
- version_requirements: *70339771535500
151
+ version_requirements: *70337700767500
152
152
  - !ruby/object:Gem::Dependency
153
153
  name: hoe-highline
154
- requirement: &70339771535040 !ruby/object:Gem::Requirement
154
+ requirement: &70337700766940 !ruby/object:Gem::Requirement
155
155
  none: false
156
156
  requirements:
157
157
  - - ~>
@@ -159,10 +159,10 @@ dependencies:
159
159
  version: 0.0.1
160
160
  type: :development
161
161
  prerelease: false
162
- version_requirements: *70339771535040
162
+ version_requirements: *70337700766940
163
163
  - !ruby/object:Gem::Dependency
164
164
  name: configurability
165
- requirement: &70339771534580 !ruby/object:Gem::Requirement
165
+ requirement: &70337700766400 !ruby/object:Gem::Requirement
166
166
  none: false
167
167
  requirements:
168
168
  - - ~>
@@ -170,10 +170,10 @@ dependencies:
170
170
  version: '1.0'
171
171
  type: :development
172
172
  prerelease: false
173
- version_requirements: *70339771534580
173
+ version_requirements: *70337700766400
174
174
  - !ruby/object:Gem::Dependency
175
175
  name: rspec
176
- requirement: &70339771534040 !ruby/object:Gem::Requirement
176
+ requirement: &70337700765860 !ruby/object:Gem::Requirement
177
177
  none: false
178
178
  requirements:
179
179
  - - ~>
@@ -181,29 +181,29 @@ dependencies:
181
181
  version: '2.8'
182
182
  type: :development
183
183
  prerelease: false
184
- version_requirements: *70339771534040
184
+ version_requirements: *70337700765860
185
185
  - !ruby/object:Gem::Dependency
186
- name: hoe
187
- requirement: &70339771533600 !ruby/object:Gem::Requirement
186
+ name: rdoc
187
+ requirement: &70337700765360 !ruby/object:Gem::Requirement
188
188
  none: false
189
189
  requirements:
190
190
  - - ~>
191
191
  - !ruby/object:Gem::Version
192
- version: '2.12'
192
+ version: '3.10'
193
193
  type: :development
194
194
  prerelease: false
195
- version_requirements: *70339771533600
195
+ version_requirements: *70337700765360
196
196
  - !ruby/object:Gem::Dependency
197
- name: rdoc
198
- requirement: &70339771667280 !ruby/object:Gem::Requirement
197
+ name: hoe
198
+ requirement: &70337700764820 !ruby/object:Gem::Requirement
199
199
  none: false
200
200
  requirements:
201
201
  - - ~>
202
202
  - !ruby/object:Gem::Version
203
- version: '3.10'
203
+ version: '2.13'
204
204
  type: :development
205
205
  prerelease: false
206
- version_requirements: *70339771667280
206
+ version_requirements: *70337700764820
207
207
  description: ! "Ruby-Mongrel2 is a complete Ruby (1.9-only) connector for \nMongrel2[http://mongrel2.org/].\n\nThis
208
208
  library includes configuration-database ORM classes, a Ruby\nimplementation of the
209
209
  'm2sh' tool, a configuration DSL for generating config\ndatabases in pure Ruby,
@@ -227,12 +227,14 @@ extensions: []
227
227
  extra_rdoc_files:
228
228
  - Manifest.txt
229
229
  - examples/README.txt
230
- - README.rdoc
230
+ - DSL.rdoc
231
231
  - History.rdoc
232
+ - README.rdoc
232
233
  files:
233
234
  - .autotest
234
235
  - .gemtest
235
236
  - ChangeLog
237
+ - DSL.rdoc
236
238
  - History.rdoc
237
239
  - Manifest.txt
238
240
  - README.rdoc
@@ -327,7 +329,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
329
  version: '0'
328
330
  requirements: []
329
331
  rubyforge_project: mongrel2
330
- rubygems_version: 1.8.14
332
+ rubygems_version: 1.8.10
331
333
  signing_key:
332
334
  specification_version: 3
333
335
  summary: Ruby-Mongrel2 is a complete Ruby (1.9-only) connector for Mongrel2[http://mongrel2.org/]
metadata.gz.sig CHANGED
Binary file