strelka 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/ChangeLog +3293 -3058
  5. data/History.rdoc +17 -0
  6. data/Manifest.txt +3 -0
  7. data/Rakefile +2 -2
  8. data/contrib/hoetemplate/lib/file_name.rb.erb +3 -2
  9. data/contrib/hoetemplate/spec/file_name_spec.rb.erb +1 -1
  10. data/examples/apps/auth-demo +1 -2
  11. data/examples/apps/auth-demo2 +1 -2
  12. data/examples/apps/sessions-demo +1 -2
  13. data/examples/gen-config.rb +1 -2
  14. data/lib/strelka.rb +92 -17
  15. data/lib/strelka/app.rb +7 -6
  16. data/lib/strelka/app/auth.rb +5 -5
  17. data/lib/strelka/app/errors.rb +1 -1
  18. data/lib/strelka/app/filters.rb +1 -1
  19. data/lib/strelka/app/negotiation.rb +1 -1
  20. data/lib/strelka/app/parameters.rb +1 -1
  21. data/lib/strelka/app/restresources.rb +14 -21
  22. data/lib/strelka/app/routing.rb +5 -6
  23. data/lib/strelka/app/sessions.rb +3 -1
  24. data/lib/strelka/app/templating.rb +1 -1
  25. data/lib/strelka/authprovider.rb +1 -1
  26. data/lib/strelka/authprovider/basic.rb +1 -0
  27. data/lib/strelka/authprovider/hostaccess.rb +1 -0
  28. data/lib/strelka/behavior/plugin.rb +2 -2
  29. data/lib/strelka/cli.rb +2 -1
  30. data/lib/strelka/command/config.rb +2 -1
  31. data/lib/strelka/command/discover.rb +2 -1
  32. data/lib/strelka/command/start.rb +2 -1
  33. data/lib/strelka/constants.rb +1 -1
  34. data/lib/strelka/cookie.rb +1 -1
  35. data/lib/strelka/cookieset.rb +1 -1
  36. data/lib/strelka/discovery.rb +1 -1
  37. data/lib/strelka/httprequest.rb +4 -4
  38. data/lib/strelka/httprequest/acceptparams.rb +1 -1
  39. data/lib/strelka/httprequest/auth.rb +3 -1
  40. data/lib/strelka/httprequest/negotiation.rb +1 -1
  41. data/lib/strelka/httprequest/session.rb +3 -1
  42. data/lib/strelka/httpresponse.rb +2 -3
  43. data/lib/strelka/httpresponse/negotiation.rb +1 -1
  44. data/lib/strelka/httpresponse/session.rb +1 -1
  45. data/lib/strelka/mixins.rb +26 -5
  46. data/lib/strelka/multipartparser.rb +3 -3
  47. data/lib/strelka/paramvalidator.rb +4 -4
  48. data/lib/strelka/plugins.rb +14 -5
  49. data/lib/strelka/router.rb +1 -1
  50. data/lib/strelka/router/default.rb +1 -1
  51. data/lib/strelka/router/exclusive.rb +1 -1
  52. data/lib/strelka/session.rb +1 -0
  53. data/lib/strelka/session/db.rb +1 -0
  54. data/lib/strelka/session/default.rb +1 -0
  55. data/lib/strelka/testing.rb +454 -14
  56. data/lib/strelka/websocketserver.rb +150 -36
  57. data/lib/strelka/websocketserver/heartbeat.rb +163 -0
  58. data/lib/strelka/websocketserver/routing.rb +46 -19
  59. data/spec/constants.rb +1 -1
  60. data/spec/helpers.rb +15 -6
  61. data/spec/strelka/app/auth_spec.rb +5 -3
  62. data/spec/strelka/app/errors_spec.rb +2 -2
  63. data/spec/strelka/app/filters_spec.rb +2 -2
  64. data/spec/strelka/app/negotiation_spec.rb +2 -2
  65. data/spec/strelka/app/parameters_spec.rb +5 -5
  66. data/spec/strelka/app/restresources_spec.rb +8 -6
  67. data/spec/strelka/app/routing_spec.rb +3 -3
  68. data/spec/strelka/app/sessions_spec.rb +4 -2
  69. data/spec/strelka/app/templating_spec.rb +2 -2
  70. data/spec/strelka/app_spec.rb +5 -24
  71. data/spec/strelka/authprovider/basic_spec.rb +3 -2
  72. data/spec/strelka/authprovider/hostaccess_spec.rb +3 -2
  73. data/spec/strelka/authprovider_spec.rb +3 -2
  74. data/spec/strelka/cli_spec.rb +7 -4
  75. data/spec/strelka/cookie_spec.rb +2 -2
  76. data/spec/strelka/cookieset_spec.rb +2 -2
  77. data/spec/strelka/discovery_spec.rb +2 -2
  78. data/spec/strelka/exceptions_spec.rb +2 -2
  79. data/spec/strelka/httprequest/acceptparams_spec.rb +2 -2
  80. data/spec/strelka/httprequest/auth_spec.rb +3 -2
  81. data/spec/strelka/httprequest/negotiation_spec.rb +2 -2
  82. data/spec/strelka/httprequest/session_spec.rb +3 -2
  83. data/spec/strelka/httprequest_spec.rb +7 -2
  84. data/spec/strelka/httpresponse/negotiation_spec.rb +6 -5
  85. data/spec/strelka/httpresponse/session_spec.rb +3 -2
  86. data/spec/strelka/httpresponse_spec.rb +4 -3
  87. data/spec/strelka/mixins_spec.rb +85 -2
  88. data/spec/strelka/multipartparser_spec.rb +5 -4
  89. data/spec/strelka/paramvalidator_spec.rb +15 -10
  90. data/spec/strelka/plugins_spec.rb +24 -2
  91. data/spec/strelka/router/default_spec.rb +2 -2
  92. data/spec/strelka/router/exclusive_spec.rb +2 -2
  93. data/spec/strelka/router_spec.rb +2 -2
  94. data/spec/strelka/session/db_spec.rb +3 -2
  95. data/spec/strelka/session/default_spec.rb +3 -2
  96. data/spec/strelka/session_spec.rb +3 -2
  97. data/spec/strelka/testing_spec.rb +772 -0
  98. data/spec/strelka/websocketserver/heartbeat_spec.rb +19 -0
  99. data/spec/strelka/websocketserver/routing_spec.rb +31 -29
  100. data/spec/strelka/websocketserver_spec.rb +210 -75
  101. data/spec/strelka_spec.rb +172 -2
  102. metadata +43 -36
  103. metadata.gz.sig +0 -0
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'loggability'
6
6
 
@@ -235,9 +235,7 @@ module Strelka::App::Routing
235
235
  def split_route_pattern( pattern )
236
236
  return [pattern] if pattern.is_a?( Regexp )
237
237
 
238
- pattern.slice!( 0, 1 ) if pattern.start_with?( '/' )
239
-
240
- return pattern.split( '/' ).collect do |component|
238
+ return pattern.split( '/' ).reject( &:empty? ).collect do |component|
241
239
 
242
240
  if component.start_with?( ':' )
243
241
  self.log.debug "translating parameter component %p to a regexp" % [component]
@@ -256,10 +254,11 @@ module Strelka::App::Routing
256
254
  ### Generate a name based on the parts of the given +pattern+.
257
255
  def make_route_name( pattern )
258
256
  name = '_re_'
257
+
259
258
  if pattern.names.empty?
260
- name << ("%s%#x" % [ pattern.class.name, pattern.object_id * 2 ])
259
+ name += ("%s%#x" % [ pattern.class.name, pattern.object_id * 2 ])
261
260
  else
262
- name << pattern.names.join( '_' )
261
+ name += pattern.names.join( '_' )
263
262
  end
264
263
 
265
264
  return name
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen_string_literal: true
2
4
 
3
5
  require 'loggability'
4
6
 
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'inversion'
6
6
 
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'pluggability'
6
6
 
@@ -1,5 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
+ # frozen-string-literal: true
3
4
 
4
5
  require 'openssl'
5
6
  require 'configurability'
@@ -1,5 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
+ # frozen-string-literal: true
3
4
 
4
5
  require 'ipaddr'
5
6
  require 'loggability'
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'rspec'
6
6
 
@@ -22,7 +22,7 @@ require 'strelka/plugins'
22
22
  #
23
23
  # end
24
24
 
25
- shared_examples_for "A Strelka Plugin" do
25
+ RSpec.shared_examples_for "A Strelka Plugin" do
26
26
 
27
27
  let( :plugin ) do
28
28
  described_class
@@ -1,5 +1,6 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen-string-literal: true
3
4
 
4
5
  require 'loggability'
5
6
  require 'highline'
@@ -1,5 +1,6 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen-string-literal: true
3
4
 
4
5
  require 'strelka/cli' unless defined?( Strelka::CLI )
5
6
 
@@ -1,5 +1,6 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen-string-literal: true
3
4
 
4
5
  require 'strelka/cli' unless defined?( Strelka::CLI )
5
6
 
@@ -1,5 +1,6 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen-string-literal: true
3
4
 
4
5
  require 'strelka/cli' unless defined?( Strelka::CLI )
5
6
 
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'uri'
6
6
  require 'mongrel2/constants'
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'date'
6
6
  require 'time'
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'set'
6
6
  require 'forwardable'
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'rubygems'
6
6
  require 'strelka' unless defined?( Strelka )
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'yajl'
6
6
  require 'safe_yaml'
@@ -92,7 +92,7 @@ class Strelka::HTTPRequest < Mongrel2::HTTPRequest
92
92
  ### request.base_uri
93
93
  ### # => #<URI::HTTP:0x007fe34d16b2e0 URL:http://localhost:8080/user>
94
94
  def base_uri
95
- rval = self.uri
95
+ rval = self.uri.dup
96
96
  rval.path = self.headers.pattern
97
97
  rval.query = nil
98
98
  return rval
@@ -107,7 +107,7 @@ class Strelka::HTTPRequest < Mongrel2::HTTPRequest
107
107
  ### request.route
108
108
  ### # => "/user"
109
109
  def route
110
- return URI.unescape( self.headers.pattern )
110
+ return URI.decode_www_form_component( self.headers.pattern )
111
111
  end
112
112
  alias_method :pattern, :route
113
113
 
@@ -119,7 +119,7 @@ class Strelka::HTTPRequest < Mongrel2::HTTPRequest
119
119
  ### request.app_path
120
120
  ### # => "/1/profile"
121
121
  def app_path
122
- rval = URI.unescape( self.uri.path )
122
+ rval = URI.decode_www_form_component( self.uri.path )
123
123
  rval.slice!( 0, self.route.bytesize )
124
124
  return rval
125
125
  end
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'loggability'
6
6
  require 'strelka/mixins'
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen-string-literal: true
2
4
 
3
5
  require 'strelka/constants'
4
6
  require 'strelka/httprequest' unless defined?( Strelka::HTTPRequest )
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'strelka/constants'
6
6
  require 'strelka/httprequest' unless defined?( Strelka::HTTPRequest )
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen-string-literal: true
2
4
 
3
5
  require 'configurability'
4
6
 
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'loggability'
6
6
  require 'mongrel2/httpresponse'
@@ -117,8 +117,7 @@ class Strelka::HTTPResponse < Mongrel2::HTTPResponse
117
117
  charset = self.find_header_charset
118
118
  self.log.debug "Setting the charset in the content-type header to: %p" % [ charset.name ]
119
119
 
120
- headers.content_type.slice!( CONTENT_TYPE_CHARSET_RE ) and
121
- self.log.debug " removed old charset parameter."
120
+ headers.content_type = headers.content_type.sub( CONTENT_TYPE_CHARSET_RE, '' )
122
121
  headers.content_type += "; charset=#{charset.name}" unless
123
122
  charset == Encoding::ASCII_8BIT
124
123
  end
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'set'
6
6
  require 'yaml'
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'strelka/constants'
6
6
  require 'strelka/exceptions'
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
 
6
6
  require 'tempfile'
@@ -279,19 +279,30 @@ module Strelka
279
279
  ### declaring object (e.g., class instance variables and methods if declared
280
280
  ### in a Class).
281
281
  def singleton_attr_reader( *symbols )
282
- symbols.each do |sym|
283
- singleton_class.__send__( :attr_reader, sym )
282
+ singleton_class.instance_exec( symbols ) do |attrs|
283
+ attr_reader( *attrs )
284
284
  end
285
285
  end
286
286
 
287
+
288
+ ### Create instance variables and corresponding methods that return
289
+ ### true or false values for each of the specified +symbols+ in the singleton
290
+ ### of the declaring object.
291
+ def singleton_predicate_reader( *symbols )
292
+ singleton_class.extend( Strelka::MethodUtilities )
293
+ singleton_class.attr_predicate( *symbols )
294
+ end
295
+
296
+
287
297
  ### Creates methods that allow assignment to the attributes of the singleton
288
298
  ### of the declaring object that correspond to the specified +symbols+.
289
299
  def singleton_attr_writer( *symbols )
290
- symbols.each do |sym|
291
- singleton_class.__send__( :attr_writer, sym )
300
+ singleton_class.instance_exec( symbols ) do |attrs|
301
+ attr_writer( *attrs )
292
302
  end
293
303
  end
294
304
 
305
+
295
306
  ### Creates readers and writers that allow assignment to the attributes of
296
307
  ### the singleton of the declaring object that correspond to the specified
297
308
  ### +symbols+.
@@ -301,6 +312,16 @@ module Strelka
301
312
  end
302
313
  end
303
314
 
315
+
316
+ ### Create predicate methods and writers that allow assignment to the attributes
317
+ ### of the singleton of the declaring object that correspond to the specified
318
+ ### +symbols+.
319
+ def singleton_predicate_accessor( *symbols )
320
+ singleton_class.extend( Strelka::MethodUtilities )
321
+ singleton_class.attr_predicate_accessor( *symbols )
322
+ end
323
+
324
+
304
325
  ### Creates an alias for the +original+ method named +newname+.
305
326
  def singleton_method_alias( newname, original )
306
327
  singleton_class.__send__( :alias_method, newname, original )
@@ -1,6 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'tmpdir'
6
6
  require 'tempfile'
@@ -79,7 +79,7 @@ class Strelka::MultipartParser
79
79
  @io = io
80
80
  @boundary = boundary
81
81
  @fields = {}
82
- @buffer = ''
82
+ @buffer = String.new( encoding: io.internal_encoding || io.external_encoding )
83
83
 
84
84
  # Ensure that the buffer can contain at least a whole boundary,
85
85
  # otherwise we can't scan for it.
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'uri'
6
6
  require 'forwardable'
@@ -208,7 +208,7 @@ class Strelka::ParamValidator
208
208
 
209
209
  if self.block
210
210
  location = self.block.source_location
211
- desc << " on line %d of %s" % [ location[1], location[0] ]
211
+ desc += " on line %d of %s" % [ location[1], location[0] ]
212
212
  end
213
213
 
214
214
  return desc
@@ -419,8 +419,8 @@ class Strelka::ParamValidator
419
419
  :float => /^(?<float>[\-\+]?(?:\d*\.\d+|\d+)(?:e[\-\+]?\d+)?)$/i,
420
420
  :alpha => /^(?<alpha>[[:alpha:]]+)$/,
421
421
  :alphanumeric => /^(?<alphanumeric>[[:alnum:]]+)$/,
422
- :printable => /\A(?<printable>[[:print:][:blank:]\r\n]+)\z/,
423
- :string => /\A(?<string>[[:print:][:blank:]\r\n]+)\z/,
422
+ :printable => /\A(?<printable>[[:print:][:space:]]+)\z/,
423
+ :string => /\A(?<string>[[:print:][:space:]]+)\z/,
424
424
  :word => /^(?<word>[[:word:]]+)$/,
425
425
  :email => /^(?<email>#{RFC822_EMAIL_ADDRESS})$/,
426
426
  :hostname => /^(?<hostname>#{RFC1738_HOSTNAME})$/,
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'set'
6
6
  require 'tsort'
@@ -80,7 +80,7 @@ module Strelka
80
80
  ### Return the name of the receiving plugin
81
81
  def plugin_name
82
82
  name = self.name || "anonymous#{self.object_id}"
83
- name.sub!( /.*::/, '' )
83
+ name = name.sub( /.*::/, '' )
84
84
  return name.downcase.to_sym
85
85
  end
86
86
 
@@ -167,7 +167,7 @@ module Strelka
167
167
 
168
168
 
169
169
  ### Load the plugins with the given +names+ and install them.
170
- def plugins( *names )
170
+ def plugins( *names, &block )
171
171
  self.log.info "Adding plugins: %s" % [ names.flatten.map(&:to_s).join(', ') ]
172
172
 
173
173
  # Load the associated Plugin Module objects
@@ -187,7 +187,7 @@ module Strelka
187
187
  end
188
188
 
189
189
  self.log.debug " registering %p" % [ name ]
190
- self.register_plugin( plugin )
190
+ self.register_plugin( plugin, &block )
191
191
  end
192
192
  end
193
193
  alias_method :plugin, :plugins
@@ -214,7 +214,7 @@ module Strelka
214
214
  ### Register the plugin +mod+ in the receiving class. This adds any
215
215
  ### declaratives and class-level data necessary for configuring the
216
216
  ### plugin.
217
- def register_plugin( mod )
217
+ def register_plugin( mod, &block )
218
218
  if mod.const_defined?( :ClassMethods )
219
219
  cm_mod = mod.const_get(:ClassMethods)
220
220
  self.log.debug " adding class methods from %p" % [ cm_mod ]
@@ -233,6 +233,15 @@ module Strelka
233
233
  [ ivar, self.instance_variable_get(ivar), self ]
234
234
  end
235
235
  end
236
+
237
+ if block
238
+ if mod.respond_to?( :configure_block )
239
+ mod.configure_block( self, &block )
240
+ else
241
+ self.log.warn "Blocked passed to %p, which doesn't support block config." %
242
+ [ mod ]
243
+ end
244
+ end
236
245
  end
237
246
 
238
247
 
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'loggability'
6
6
  require 'pluggability'
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
3
+ # frozen-string-literal: true
4
4
 
5
5
  require 'loggability'
6
6