strelka 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ChangeLog +3293 -3058
- data/History.rdoc +17 -0
- data/Manifest.txt +3 -0
- data/Rakefile +2 -2
- data/contrib/hoetemplate/lib/file_name.rb.erb +3 -2
- data/contrib/hoetemplate/spec/file_name_spec.rb.erb +1 -1
- data/examples/apps/auth-demo +1 -2
- data/examples/apps/auth-demo2 +1 -2
- data/examples/apps/sessions-demo +1 -2
- data/examples/gen-config.rb +1 -2
- data/lib/strelka.rb +92 -17
- data/lib/strelka/app.rb +7 -6
- data/lib/strelka/app/auth.rb +5 -5
- data/lib/strelka/app/errors.rb +1 -1
- data/lib/strelka/app/filters.rb +1 -1
- data/lib/strelka/app/negotiation.rb +1 -1
- data/lib/strelka/app/parameters.rb +1 -1
- data/lib/strelka/app/restresources.rb +14 -21
- data/lib/strelka/app/routing.rb +5 -6
- data/lib/strelka/app/sessions.rb +3 -1
- data/lib/strelka/app/templating.rb +1 -1
- data/lib/strelka/authprovider.rb +1 -1
- data/lib/strelka/authprovider/basic.rb +1 -0
- data/lib/strelka/authprovider/hostaccess.rb +1 -0
- data/lib/strelka/behavior/plugin.rb +2 -2
- data/lib/strelka/cli.rb +2 -1
- data/lib/strelka/command/config.rb +2 -1
- data/lib/strelka/command/discover.rb +2 -1
- data/lib/strelka/command/start.rb +2 -1
- data/lib/strelka/constants.rb +1 -1
- data/lib/strelka/cookie.rb +1 -1
- data/lib/strelka/cookieset.rb +1 -1
- data/lib/strelka/discovery.rb +1 -1
- data/lib/strelka/httprequest.rb +4 -4
- data/lib/strelka/httprequest/acceptparams.rb +1 -1
- data/lib/strelka/httprequest/auth.rb +3 -1
- data/lib/strelka/httprequest/negotiation.rb +1 -1
- data/lib/strelka/httprequest/session.rb +3 -1
- data/lib/strelka/httpresponse.rb +2 -3
- data/lib/strelka/httpresponse/negotiation.rb +1 -1
- data/lib/strelka/httpresponse/session.rb +1 -1
- data/lib/strelka/mixins.rb +26 -5
- data/lib/strelka/multipartparser.rb +3 -3
- data/lib/strelka/paramvalidator.rb +4 -4
- data/lib/strelka/plugins.rb +14 -5
- data/lib/strelka/router.rb +1 -1
- data/lib/strelka/router/default.rb +1 -1
- data/lib/strelka/router/exclusive.rb +1 -1
- data/lib/strelka/session.rb +1 -0
- data/lib/strelka/session/db.rb +1 -0
- data/lib/strelka/session/default.rb +1 -0
- data/lib/strelka/testing.rb +454 -14
- data/lib/strelka/websocketserver.rb +150 -36
- data/lib/strelka/websocketserver/heartbeat.rb +163 -0
- data/lib/strelka/websocketserver/routing.rb +46 -19
- data/spec/constants.rb +1 -1
- data/spec/helpers.rb +15 -6
- data/spec/strelka/app/auth_spec.rb +5 -3
- data/spec/strelka/app/errors_spec.rb +2 -2
- data/spec/strelka/app/filters_spec.rb +2 -2
- data/spec/strelka/app/negotiation_spec.rb +2 -2
- data/spec/strelka/app/parameters_spec.rb +5 -5
- data/spec/strelka/app/restresources_spec.rb +8 -6
- data/spec/strelka/app/routing_spec.rb +3 -3
- data/spec/strelka/app/sessions_spec.rb +4 -2
- data/spec/strelka/app/templating_spec.rb +2 -2
- data/spec/strelka/app_spec.rb +5 -24
- data/spec/strelka/authprovider/basic_spec.rb +3 -2
- data/spec/strelka/authprovider/hostaccess_spec.rb +3 -2
- data/spec/strelka/authprovider_spec.rb +3 -2
- data/spec/strelka/cli_spec.rb +7 -4
- data/spec/strelka/cookie_spec.rb +2 -2
- data/spec/strelka/cookieset_spec.rb +2 -2
- data/spec/strelka/discovery_spec.rb +2 -2
- data/spec/strelka/exceptions_spec.rb +2 -2
- data/spec/strelka/httprequest/acceptparams_spec.rb +2 -2
- data/spec/strelka/httprequest/auth_spec.rb +3 -2
- data/spec/strelka/httprequest/negotiation_spec.rb +2 -2
- data/spec/strelka/httprequest/session_spec.rb +3 -2
- data/spec/strelka/httprequest_spec.rb +7 -2
- data/spec/strelka/httpresponse/negotiation_spec.rb +6 -5
- data/spec/strelka/httpresponse/session_spec.rb +3 -2
- data/spec/strelka/httpresponse_spec.rb +4 -3
- data/spec/strelka/mixins_spec.rb +85 -2
- data/spec/strelka/multipartparser_spec.rb +5 -4
- data/spec/strelka/paramvalidator_spec.rb +15 -10
- data/spec/strelka/plugins_spec.rb +24 -2
- data/spec/strelka/router/default_spec.rb +2 -2
- data/spec/strelka/router/exclusive_spec.rb +2 -2
- data/spec/strelka/router_spec.rb +2 -2
- data/spec/strelka/session/db_spec.rb +3 -2
- data/spec/strelka/session/default_spec.rb +3 -2
- data/spec/strelka/session_spec.rb +3 -2
- data/spec/strelka/testing_spec.rb +772 -0
- data/spec/strelka/websocketserver/heartbeat_spec.rb +19 -0
- data/spec/strelka/websocketserver/routing_spec.rb +31 -29
- data/spec/strelka/websocketserver_spec.rb +210 -75
- data/spec/strelka_spec.rb +172 -2
- metadata +43 -36
- metadata.gz.sig +0 -0
data/lib/strelka/app/routing.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
#
|
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.
|
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
|
259
|
+
name += ("%s%#x" % [ pattern.class.name, pattern.object_id * 2 ])
|
261
260
|
else
|
262
|
-
name
|
261
|
+
name += pattern.names.join( '_' )
|
263
262
|
end
|
264
263
|
|
265
264
|
return name
|
data/lib/strelka/app/sessions.rb
CHANGED
data/lib/strelka/authprovider.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
#
|
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
|
data/lib/strelka/cli.rb
CHANGED
data/lib/strelka/constants.rb
CHANGED
data/lib/strelka/cookie.rb
CHANGED
data/lib/strelka/cookieset.rb
CHANGED
data/lib/strelka/discovery.rb
CHANGED
data/lib/strelka/httprequest.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
#
|
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.
|
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.
|
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
|
data/lib/strelka/httpresponse.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
#
|
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.
|
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
|
data/lib/strelka/mixins.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
#
|
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
|
-
|
283
|
-
|
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
|
-
|
291
|
-
|
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
|
-
|
1
|
+
# -*- ruby -*-
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
#
|
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
|
-
#
|
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
|
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:][:
|
423
|
-
:string => /\A(?<string>[[:print:][:
|
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})$/,
|
data/lib/strelka/plugins.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
#
|
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
|
|
data/lib/strelka/router.rb
CHANGED