strelka 0.0.1.pre.229 → 0.0.1.pre.232

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,8 +1,32 @@
1
1
  2012-05-09 Michael Granger <ged@FaerieMUD.org>
2
2
 
3
+ * bin/strelka:
4
+ Updates for bin/strelka:
5
+ - Adding a 'config' subcommand to dump Configurability defaults for
6
+ discovered apps.
7
+ - Update for Loggability changes.
8
+ [f5c63705cd79] [github/master, tip]
9
+
10
+ * lib/strelka/app.rb, lib/strelka/app/auth.rb:
11
+ Adding support for config-discovery
12
+ [a7352e61d5f5]
13
+
14
+ * lib/strelka/app/routing.rb, spec/strelka/app/routing_spec.rb,
15
+ spec/strelka/router/default_spec.rb:
16
+ Adding support for regexp-only routes
17
+ [f74278523338]
18
+
19
+ * lib/strelka/httprequest/session.rb,
20
+ lib/strelka/httpresponse/session.rb, spec/lib/helpers.rb,
21
+ spec/strelka/app/sessions_spec.rb,
22
+ spec/strelka/httprequest/session_spec.rb,
23
+ spec/strelka/httpresponse/session_spec.rb:
24
+ Prevent unnecessary session loading and saving.
25
+ [1242808d64a6]
26
+
3
27
  * lib/strelka/cookieset.rb, spec/strelka/cookieset_spec.rb:
4
28
  Add delegation for some more Set methods to CookieSet
5
- [c88faf6871e7] [tip]
29
+ [c88faf6871e7]
6
30
 
7
31
  2012-05-08 Michael Granger <ged@FaerieMUD.org>
8
32
 
@@ -26,7 +50,7 @@
26
50
  Provide access to the request during layout template wrapping, so
27
51
  handlers can potentially override the method and attach arbitrary
28
52
  request attributes to the layout.
29
- [1fc0cf040a1e] [github/master]
53
+ [1fc0cf040a1e]
30
54
 
31
55
  2012-05-07 Michael Granger <ged@FaerieMUD.org>
32
56
 
@@ -345,18 +369,16 @@
345
369
  * Merging with ssh://hg@deveiate.org/Strelka@8f1c27819e70
346
370
  [5fcd76455aad]
347
371
 
372
+ * Manifest.txt:
373
+ Updating the manifest
374
+ [35165b3d01cc]
375
+
348
376
  2012-04-11 Mahlon E. Smith <mahlon@martini.nu>
349
377
 
350
378
  * lib/strelka/session/default.rb:
351
379
  Use the built-in securerandom method for obtaining a hex value.
352
380
  [8f1c27819e70]
353
381
 
354
- 2012-04-11 Michael Granger <ged@FaerieMUD.org>
355
-
356
- * Manifest.txt:
357
- Updating the manifest
358
- [35165b3d01cc]
359
-
360
382
  2012-04-10 Michael Granger <ged@FaerieMUD.org>
361
383
 
362
384
  * lib/strelka/app/auth.rb, lib/strelka/app/parameters.rb,
@@ -427,6 +449,22 @@
427
449
  Add the ChangeLog to the ignorefile
428
450
  [cc8c30d38652]
429
451
 
452
+ * lib/strelka/app/templating.rb:
453
+ Add API docs to the :templating plugin module
454
+ [3c160d996320]
455
+
456
+ * README.rdoc:
457
+ Add more URLs
458
+ [060962556bd1]
459
+
460
+ * Rakefile:
461
+ Oops. Fix typo
462
+ [5a8aa207860b]
463
+
464
+ * .rvm.gems, Rakefile:
465
+ Update dependencies
466
+ [787e523777d1]
467
+
430
468
  2012-04-06 Mahlon E. Smith <mahlon@martini.nu>
431
469
 
432
470
  * lib/strelka/app/sessions.rb, lib/strelka/cookie.rb,
@@ -444,24 +482,6 @@
444
482
  Add a persistent DB session store, using sequel.
445
483
  [99f3c3f5d6ca]
446
484
 
447
- 2012-04-06 Michael Granger <ged@FaerieMUD.org>
448
-
449
- * lib/strelka/app/templating.rb:
450
- Add API docs to the :templating plugin module
451
- [3c160d996320]
452
-
453
- * README.rdoc:
454
- Add more URLs
455
- [060962556bd1]
456
-
457
- * Rakefile:
458
- Oops. Fix typo
459
- [5a8aa207860b]
460
-
461
- * .rvm.gems, Rakefile:
462
- Update dependencies
463
- [787e523777d1]
464
-
465
485
  2012-04-04 Michael Granger <ged@FaerieMUD.org>
466
486
 
467
487
  * manual/src/tutorial.page:
data/bin/strelka CHANGED
@@ -4,6 +4,7 @@
4
4
  require 'strelka'
5
5
  require 'trollop'
6
6
  require 'highline'
7
+ require 'loggability'
7
8
 
8
9
  # Have to do it this way to avoid the vendored 'sysexits' under OSX.
9
10
  gem 'sysexits'
@@ -12,11 +13,16 @@ require 'sysexits'
12
13
 
13
14
  # A tool for setting up and running Strelka apps
14
15
  class Strelka::CLICommand
15
- extend ::Sysexits
16
+ extend ::Sysexits,
17
+ Loggability
16
18
  include Sysexits,
17
- Strelka::Loggable,
18
19
  Strelka::Constants
19
20
 
21
+
22
+ # Write logs to Strelka's logger
23
+ log_to :strelka
24
+
25
+
20
26
  # Make a HighLine color scheme
21
27
  COLOR_SCHEME = HighLine::ColorScheme.new do |scheme|
22
28
  scheme[:header] = [ :bold, :yellow ]
@@ -48,8 +54,8 @@ class Strelka::CLICommand
48
54
  exit :ok
49
55
 
50
56
  rescue => err
51
- Strelka.logger.fatal "Oops: %s: %s" % [ err.class.name, err.message ]
52
- Strelka.logger.debug { ' ' + err.backtrace.join("\n ") }
57
+ self.log.fatal "Oops: %s: %s" % [ err.class.name, err.message ]
58
+ self.log.debug { ' ' + err.backtrace.join("\n ") }
53
59
 
54
60
  exit :software_error
55
61
  end
@@ -89,7 +95,7 @@ class Strelka::CLICommand
89
95
  progname = File.basename( $0 )
90
96
 
91
97
  # Make a list of the log level names and the available commands
92
- loglevels = Strelka::Logging::LOG_LEVELS.
98
+ loglevels = Loggability::LOG_LEVELS.
93
99
  sort_by {|name,lvl| lvl }.
94
100
  collect {|name,lvl| name.to_s }.
95
101
  join( ', ' )
@@ -111,7 +117,7 @@ class Strelka::CLICommand
111
117
  text 'Other Options:'
112
118
  opt :debug, "Turn debugging on. Also sets the --loglevel to 'debug'."
113
119
  opt :loglevel, "Set the logging level. Must be one of: #{loglevels}",
114
- :default => Strelka::Logging::LOG_LEVEL_NAMES[ Strelka.logger.level ]
120
+ :default => Strelka.logger.level.to_s
115
121
  end
116
122
  end
117
123
 
@@ -165,15 +171,15 @@ class Strelka::CLICommand
165
171
  ### Create a new instance of the command and set it up with the given
166
172
  ### +options+.
167
173
  def initialize( options )
168
- Strelka.logger.formatter = Strelka::Logging::ColorFormatter.new( Strelka.logger ) if $stderr.tty?
174
+ Loggability.format_with( :color ) if $stderr.tty?
169
175
  @options = options
170
176
 
171
177
  if @options.debug
172
178
  $DEBUG = true
173
179
  $VERBOSE = true
174
- Strelka.logger.level = Logger::DEBUG
180
+ Loggability.level = :debug
175
181
  elsif @options.loglevel
176
- Strelka.logger.level = Strelka::Logging::LOG_LEVELS[ @options.loglevel ]
182
+ Loggability.level = @options.loglevel
177
183
  end
178
184
 
179
185
  end
@@ -311,6 +317,35 @@ class Strelka::CLICommand
311
317
  help :version, "Prints the Ruby-Mongrel2 version."
312
318
 
313
319
 
320
+ ### The 'config' command
321
+ def config_command( *args )
322
+ gemname = args.shift
323
+ discovery_name = gemname || ''
324
+
325
+ header "Dumping config for %s" % [ gemname || 'local apps' ]
326
+ discovered_apps = Strelka::App.discover_paths
327
+
328
+ raise ArgumentError, "No apps discovered" unless discovered_apps.key?( discovery_name )
329
+
330
+ discovered_apps[ discovery_name ].each do |apppath|
331
+ message " loading %s (%s)" % [ apppath, apppath.basename('.rb') ]
332
+ Strelka::App.load( apppath )
333
+
334
+ message " dumping config:"
335
+ $stdout.puts Configurability.default_config.dump
336
+ end
337
+ end
338
+ help :config, "Dump the configuration for GEMNAME (or the local directory if no gem is specified)"
339
+ usage :config, "[GEMNAME]"
340
+
341
+
342
+ ### The 'version' command
343
+ def version_command( *args )
344
+ message( "<%= color 'Version:', :header %> " + Mongrel2.version_string(true) )
345
+ end
346
+ help :version, "Prints the Ruby-Mongrel2 version."
347
+
348
+
314
349
  #
315
350
  # Helper methods
316
351
  #
@@ -240,7 +240,6 @@ require 'strelka/authprovider'
240
240
  module Strelka::App::Auth
241
241
  extend Strelka::Plugin,
242
242
  Strelka::MethodUtilities,
243
- Configurability,
244
243
  Loggability
245
244
  include Strelka::Constants
246
245
 
@@ -37,12 +37,23 @@ require 'strelka/plugins'
37
37
  #
38
38
  # # match any GET request
39
39
  # get do |req|
40
- # return req.response << 'Hello, World!'
40
+ # res = req.response
41
+ # res.puts 'Hello, World!'
42
+ # return res
41
43
  # end
42
44
  #
43
45
  # # match any GET request whose path starts with '/goodbye'
44
46
  # get '/goodbye' do |req|
45
- # return req.response << "Goodbye, cruel World!"
47
+ # res = req.response
48
+ # res.puts "Goodbye, cruel World!"
49
+ # return res
50
+ # end
51
+ #
52
+ # # match any GET request whose path ends with '.pdf'
53
+ # get /\.pdf$/ do |req|
54
+ # res = req.response
55
+ # res.body = generate_pdf()
56
+ # return res
46
57
  # end
47
58
  #
48
59
  #
@@ -64,12 +75,16 @@ require 'strelka/plugins'
64
75
  #
65
76
  # # match a GET request for the exact route only
66
77
  # get do |req|
67
- # return req.response << 'Hello, World!'
78
+ # res = req.response
79
+ # res.puts 'Hello, World!'
80
+ # return res
68
81
  # end
69
82
  #
70
83
  # # only match a GET request for '/goodbye'
71
84
  # get '/goodbye' do |req|
72
- # return req.response << "Goodbye, cruel World!"
85
+ # res = req.response
86
+ # res.puts "Goodbye, cruel World!"
87
+ # return res
73
88
  # end
74
89
  #
75
90
  # # Every other request responds with a 404
@@ -187,8 +202,8 @@ module Strelka::App::Routing
187
202
  # Make a method name from the directories and the named captures of the patterns
188
203
  # in the route
189
204
  patternparts.each do |part|
190
- if part.is_a?( Regexp )
191
- methodparts << '_' + part.names.join( '_' )
205
+ if part.respond_to?( :names )
206
+ methodparts << make_route_name( part )
192
207
  else
193
208
  methodparts << part
194
209
  end
@@ -218,6 +233,8 @@ module Strelka::App::Routing
218
233
 
219
234
  ### Split the given +pattern+ into its path components and
220
235
  def split_route_pattern( pattern )
236
+ return [pattern] if pattern.is_a?( Regexp )
237
+
221
238
  pattern.slice!( 0, 1 ) if pattern.start_with?( '/' )
222
239
 
223
240
  return pattern.split( '/' ).collect do |component|
@@ -236,6 +253,19 @@ module Strelka::App::Routing
236
253
  end
237
254
 
238
255
 
256
+ ### Generate a name based on the parts of the given +pattern+.
257
+ def make_route_name( pattern )
258
+ name = '_re_'
259
+ if pattern.names.empty?
260
+ name << ("%s%#x" % [ pattern.class.name, pattern.object_id * 2 ])
261
+ else
262
+ name << pattern.names.join( '_' )
263
+ end
264
+
265
+ return name
266
+ end
267
+
268
+
239
269
  ### Inheritance hook -- inheriting classes inherit their parents' routes table.
240
270
  def inherited( subclass )
241
271
  super
@@ -273,6 +303,7 @@ module Strelka::App::Routing
273
303
  self.log.debug "[:routing] Done with routing."
274
304
  end
275
305
 
306
+
276
307
  end # module Strelka::App::Routing
277
308
 
278
309
 
data/lib/strelka/app.rb CHANGED
@@ -27,9 +27,14 @@ class Strelka::App < Mongrel2::Handler
27
27
  # Configurability API -- use the 'app' section of the config file.
28
28
  config_key :app
29
29
 
30
+
30
31
  # Glob for matching Strelka apps relative to a gem's data directory
31
32
  APP_GLOB_PATTERN = '{apps,handlers}/**/*'
32
33
 
34
+ # Default config
35
+ CONFIG_DEFAULTS = { devmode: false }
36
+
37
+
33
38
  # Class instance variables
34
39
  @devmode = false
35
40
  @default_type = nil
@@ -182,6 +182,15 @@ describe Strelka::App::Routing do
182
182
  ]
183
183
  end
184
184
 
185
+ it "allows a route to specify a path via a Regex" do
186
+ @app.class_eval do
187
+ get /\.pdf$/ do
188
+ end
189
+ end
190
+
191
+ @app.routes.first[0,2].should == [ :GET, [/\.pdf$/] ]
192
+ end
193
+
185
194
 
186
195
  it "uses the Strelka::Router::Default as it's router by default" do
187
196
  @app.routerclass.should == :default
@@ -237,7 +246,7 @@ describe Strelka::App::Routing do
237
246
 
238
247
  @app.routes.should ==
239
248
  [[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
240
- {action: @app.instance_method(:POST_userinfo__username), options: {}} ]]
249
+ {action: @app.instance_method(:POST_userinfo__re_username), options: {}} ]]
241
250
  end
242
251
 
243
252
  it "unbinds parameter patterns bound with ^ and $ for the route" do
@@ -249,7 +258,7 @@ describe Strelka::App::Routing do
249
258
 
250
259
  @app.routes.should ==
251
260
  [[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
252
- {action: @app.instance_method(:POST_userinfo__username), options: {}} ]]
261
+ {action: @app.instance_method(:POST_userinfo__re_username), options: {}} ]]
253
262
  end
254
263
 
255
264
  it "unbinds parameter patterns bound with \\A and \\z for the route" do
@@ -261,7 +270,7 @@ describe Strelka::App::Routing do
261
270
 
262
271
  @app.routes.should ==
263
272
  [[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
264
- {action: @app.instance_method(:POST_userinfo__username), options: {}} ]]
273
+ {action: @app.instance_method(:POST_userinfo__re_username), options: {}} ]]
265
274
  end
266
275
 
267
276
  it "unbinds parameter patterns bound with \\Z for the route" do
@@ -273,7 +282,7 @@ describe Strelka::App::Routing do
273
282
 
274
283
  @app.routes.should ==
275
284
  [[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
276
- {action: @app.instance_method(:POST_userinfo__username), options: {}} ]]
285
+ {action: @app.instance_method(:POST_userinfo__re_username), options: {}} ]]
277
286
  end
278
287
 
279
288
  it "merges parameters from the route path into the request's param validator" do
@@ -227,5 +227,29 @@ describe Strelka::Router::Default do
227
227
 
228
228
  end
229
229
 
230
+ context "a router with routes for: 'foo', then '/(?<filename>\p{Print}*)\.pdf$/'" do
231
+
232
+ before( :each ) do
233
+ @router.add_route( :GET, ['foo'], route(:foo) )
234
+ @router.add_route( :GET, [/(?<filename>\p{Print}*)\.pdf$/], route(:as_pdf) )
235
+ end
236
+
237
+ it "routes /user/foo/1 to the foo action" do
238
+ req = @request_factory.get( '/user/foo/1' )
239
+ @router.route_request( req ).should match_route( :foo )
240
+ end
241
+
242
+ it "routes /foo.pdf to the regexp action" do
243
+ req = @request_factory.get( '/user/foo.pdf' )
244
+ @router.route_request( req ).should match_route( :as_pdf )
245
+ end
246
+
247
+ it "routes /zanzibar.pdf to the regexp action" do
248
+ req = @request_factory.get( '/user/zanzibar.pdf' )
249
+ @router.route_request( req ).should match_route( :as_pdf )
250
+ end
251
+
252
+ end
253
+
230
254
  end
231
255
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strelka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.229
4
+ version: 0.0.1.pre.232
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
metadata.gz.sig CHANGED
@@ -1,3 +1,4 @@
1
- =aoS5�Ɋ�)P/��!�H����аb\������G:R$x�7V���݃1
2
- o�oA)���L0��0zQ[M{�B�
3
- i�+� \��M����> ht&;����1��s=�{k�S-��1���]�� _h�u��)�C#N�7@ b�a ��<��xb���3��q*��\�k�Rp��;��,�!��ĸéL�eH
1
+ ���وe{�
2
+ ��ΎZB.�oܾ�k���R��� p
3
+ P7�/9]�� ��0c�����k��J�&�!F
4
+ �:�7 $��r���J����Pۉ���@�lߊ)}T�\���J