strelka 0.0.1.pre.219 → 0.0.1.pre.224
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/Rakefile +1 -0
- data/bin/strelka +3 -1
- data/lib/strelka.rb +8 -10
- data/lib/strelka/app.rb +18 -15
- data/lib/strelka/app/auth.rb +10 -3
- data/lib/strelka/app/routing.rb +10 -3
- data/lib/strelka/app/sessions.rb +13 -6
- data/lib/strelka/authprovider.rb +5 -2
- data/lib/strelka/authprovider/basic.rb +4 -3
- data/lib/strelka/authprovider/hostaccess.rb +6 -1
- data/lib/strelka/cookie.rb +6 -1
- data/lib/strelka/httprequest.rb +14 -3
- data/lib/strelka/httprequest/acceptparams.rb +6 -1
- data/lib/strelka/httprequest/session.rb +8 -0
- data/lib/strelka/httpresponse.rb +8 -3
- data/lib/strelka/mixins.rb +8 -81
- data/lib/strelka/paramvalidator.rb +7 -2
- data/lib/strelka/router.rb +7 -2
- data/lib/strelka/router/default.rb +4 -2
- data/lib/strelka/router/exclusive.rb +7 -1
- data/lib/strelka/session.rb +6 -2
- data/lib/strelka/session/db.rb +8 -3
- data/lib/strelka/session/default.rb +4 -3
- data/spec/lib/helpers.rb +11 -18
- data/spec/strelka/httprequest/session_spec.rb +6 -1
- data/spec/strelka/httprequest_spec.rb +10 -0
- data/spec/strelka/mixins_spec.rb +0 -34
- metadata +18 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
|
Binary file
|
data/Rakefile
CHANGED
|
@@ -31,6 +31,7 @@ hoespec = Hoe.spec 'strelka' do
|
|
|
31
31
|
self.dependency 'uuidtools', '~> 2.1'
|
|
32
32
|
self.dependency 'configurability', '~> 1.0'
|
|
33
33
|
self.dependency 'pluginfactory', '~> 1.0'
|
|
34
|
+
self.dependency 'loggability', '~> 0.0'
|
|
34
35
|
|
|
35
36
|
self.dependency 'hoe-deveiate', '~> 0.1', :developer
|
|
36
37
|
self.dependency 'hoe-manualgen', '~> 0.3', :developer
|
data/bin/strelka
CHANGED
|
@@ -293,7 +293,9 @@ class Strelka::CLICommand
|
|
|
293
293
|
fork do
|
|
294
294
|
self.log.debug " in the child."
|
|
295
295
|
Strelka.load_config( self.options.config ) if self.options.config
|
|
296
|
-
|
|
296
|
+
apps = Strelka::App.load( path )
|
|
297
|
+
self.log.debug " loaded: %p" % [ apps ]
|
|
298
|
+
apps.first.run
|
|
297
299
|
end
|
|
298
300
|
|
|
299
301
|
message "started. Waiting for shutdown."
|
data/lib/strelka.rb
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
# encoding: utf-8
|
|
4
4
|
|
|
5
5
|
require 'mongrel2'
|
|
6
|
+
require 'loggability'
|
|
6
7
|
require 'configurability'
|
|
7
8
|
require 'configurability/config'
|
|
8
9
|
|
|
10
|
+
|
|
9
11
|
# A Ruby application framework for Mongrel2[http://mongrel2.org/].
|
|
10
12
|
#
|
|
11
13
|
# == Author/s
|
|
@@ -16,20 +18,16 @@ require 'configurability/config'
|
|
|
16
18
|
# :main: README.rdoc
|
|
17
19
|
#
|
|
18
20
|
module Strelka
|
|
21
|
+
extend Loggability
|
|
22
|
+
|
|
23
|
+
# Loggability API -- Set up this module as a log host.
|
|
24
|
+
log_as :strelka
|
|
19
25
|
|
|
20
26
|
# Library version constant
|
|
21
27
|
VERSION = '0.0.1'
|
|
22
28
|
|
|
23
29
|
# Version-control revision constant
|
|
24
|
-
REVISION = %q$Revision:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
require 'strelka/logging'
|
|
28
|
-
extend Strelka::Logging
|
|
29
|
-
|
|
30
|
-
# Combine Strelka, Mongrel2, and Configurability logging
|
|
31
|
-
Mongrel2.logger = Strelka.logger
|
|
32
|
-
Configurability.logger = Strelka.logger
|
|
30
|
+
REVISION = %q$Revision: 4f0cbd7b3070 $
|
|
33
31
|
|
|
34
32
|
require 'strelka/constants'
|
|
35
33
|
include Strelka::Constants
|
|
@@ -73,7 +71,7 @@ module Strelka
|
|
|
73
71
|
### Convenience method -- Load the Configurability::Config from +configfile+
|
|
74
72
|
### and install it.
|
|
75
73
|
def self::load_config( configfile, defaults={} )
|
|
76
|
-
|
|
74
|
+
self.log.info "Loading universal config from %p" % [ configfile ]
|
|
77
75
|
self.config = Configurability::Config.load( configfile, defaults )
|
|
78
76
|
self.config.install
|
|
79
77
|
end
|
data/lib/strelka/app.rb
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
require 'rubygems' # For the Rubygems API
|
|
6
6
|
|
|
7
|
+
require 'loggability'
|
|
7
8
|
require 'configurability'
|
|
8
9
|
require 'mongrel2/handler'
|
|
9
10
|
require 'strelka' unless defined?( Strelka )
|
|
@@ -13,13 +14,15 @@ require 'strelka/plugins'
|
|
|
13
14
|
|
|
14
15
|
# The Strelka HTTP application base class.
|
|
15
16
|
class Strelka::App < Mongrel2::Handler
|
|
16
|
-
extend
|
|
17
|
+
extend Loggability,
|
|
18
|
+
Configurability,
|
|
17
19
|
Strelka::MethodUtilities,
|
|
18
20
|
Strelka::PluginLoader
|
|
19
|
-
include Strelka::
|
|
20
|
-
Strelka::Constants,
|
|
21
|
+
include Strelka::Constants,
|
|
21
22
|
Strelka::ResponseHelpers
|
|
22
23
|
|
|
24
|
+
# Loggability API -- set up logging
|
|
25
|
+
log_to :strelka
|
|
23
26
|
|
|
24
27
|
# Configurability API -- use the 'app' section of the config file.
|
|
25
28
|
config_key :app
|
|
@@ -59,10 +62,10 @@ class Strelka::App < Mongrel2::Handler
|
|
|
59
62
|
def self::run( appid=nil )
|
|
60
63
|
appid ||= self.default_appid
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
Loggability.level = :debug if self.devmode?
|
|
66
|
+
Loggability.format_with( :color ) if $stderr.tty?
|
|
64
67
|
|
|
65
|
-
|
|
68
|
+
self.log.info "Starting up with appid %p." % [ appid ]
|
|
66
69
|
super( appid )
|
|
67
70
|
end
|
|
68
71
|
|
|
@@ -167,6 +170,15 @@ class Strelka::App < Mongrel2::Handler
|
|
|
167
170
|
end
|
|
168
171
|
|
|
169
172
|
|
|
173
|
+
### Returns +true+ if the application has been configured to run in 'developer mode'.
|
|
174
|
+
### Developer mode is mostly informational by default (it just makes logging more
|
|
175
|
+
### verbose), but plugins and such might alter their behavior based on this setting.
|
|
176
|
+
def self::devmode?
|
|
177
|
+
return @devmode
|
|
178
|
+
end
|
|
179
|
+
singleton_method_alias :in_devmode?, :devmode?
|
|
180
|
+
|
|
181
|
+
|
|
170
182
|
### Configure the App. Override this if you wish to add additional configuration
|
|
171
183
|
### to the 'app' section of the config that will be passed to you when the config
|
|
172
184
|
### is loaded.
|
|
@@ -181,15 +193,6 @@ class Strelka::App < Mongrel2::Handler
|
|
|
181
193
|
end
|
|
182
194
|
|
|
183
195
|
|
|
184
|
-
### Returns +true+ if the application has been configured to run in 'developer mode'.
|
|
185
|
-
### Developer mode is mostly informational by default (it just makes logging more
|
|
186
|
-
### verbose), but plugins and such might alter their behavior based on this setting.
|
|
187
|
-
def self::devmode?
|
|
188
|
-
return @devmode
|
|
189
|
-
end
|
|
190
|
-
singleton_method_alias :in_devmode?, :devmode?
|
|
191
|
-
|
|
192
|
-
|
|
193
196
|
#
|
|
194
197
|
# :section: Application declarative methods
|
|
195
198
|
#
|
data/lib/strelka/app/auth.rb
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
#encoding: utf-8
|
|
4
4
|
|
|
5
|
+
require 'loggability'
|
|
6
|
+
|
|
5
7
|
require 'strelka' unless defined?( Strelka )
|
|
6
8
|
require 'strelka/app' unless defined?( Strelka::App )
|
|
7
9
|
require 'strelka/plugins'
|
|
@@ -238,10 +240,15 @@ require 'strelka/authprovider'
|
|
|
238
240
|
module Strelka::App::Auth
|
|
239
241
|
extend Strelka::Plugin,
|
|
240
242
|
Strelka::MethodUtilities,
|
|
241
|
-
Configurability
|
|
242
|
-
|
|
243
|
-
|
|
243
|
+
Configurability,
|
|
244
|
+
Loggability
|
|
245
|
+
include Strelka::Constants
|
|
246
|
+
|
|
247
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
248
|
+
log_to :strelka
|
|
249
|
+
|
|
244
250
|
|
|
251
|
+
# Plugins API -- Set up load order
|
|
245
252
|
run_before :routing, :restresources
|
|
246
253
|
run_after :templating, :errors, :sessions
|
|
247
254
|
|
data/lib/strelka/app/routing.rb
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
# encoding: utf-8
|
|
4
4
|
|
|
5
|
+
require 'loggability'
|
|
6
|
+
|
|
5
7
|
require 'strelka' unless defined?( Strelka )
|
|
6
8
|
require 'strelka/app' unless defined?( Strelka::App )
|
|
7
9
|
|
|
@@ -80,10 +82,15 @@ require 'strelka/plugins'
|
|
|
80
82
|
# routing strategies.
|
|
81
83
|
#
|
|
82
84
|
module Strelka::App::Routing
|
|
83
|
-
extend
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
extend Loggability,
|
|
86
|
+
Strelka::Plugin
|
|
87
|
+
include Strelka::Constants
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
91
|
+
log_to :strelka
|
|
86
92
|
|
|
93
|
+
# Plugins API -- set up load order
|
|
87
94
|
run_after :templating, :filters, :parameters
|
|
88
95
|
|
|
89
96
|
|
data/lib/strelka/app/sessions.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
+
require 'loggability'
|
|
4
|
+
|
|
3
5
|
require 'strelka' unless defined?( Strelka )
|
|
4
6
|
require 'strelka/app' unless defined?( Strelka::App )
|
|
5
7
|
|
|
@@ -80,20 +82,25 @@ require 'strelka/httpresponse/session'
|
|
|
80
82
|
module Strelka::App::Sessions
|
|
81
83
|
extend Strelka::Plugin,
|
|
82
84
|
Strelka::MethodUtilities,
|
|
83
|
-
Configurability
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
Configurability,
|
|
86
|
+
Loggability
|
|
87
|
+
include Strelka::Constants
|
|
86
88
|
|
|
87
|
-
#
|
|
88
|
-
|
|
89
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
90
|
+
log_to :strelka
|
|
89
91
|
|
|
90
92
|
# Configurability API -- specify which section of the config this class gets
|
|
91
93
|
config_key :sessions
|
|
92
94
|
|
|
93
|
-
# Specify load order; run as late as possible so other plugins
|
|
95
|
+
# Plugins API -- Specify load order; run as late as possible so other plugins
|
|
96
|
+
# can use the session
|
|
94
97
|
run_after :templating, :filters, :parameters
|
|
95
98
|
|
|
96
99
|
|
|
100
|
+
# Default options to pass to the session object
|
|
101
|
+
DEFAULT_OPTIONS = {}
|
|
102
|
+
|
|
103
|
+
|
|
97
104
|
##
|
|
98
105
|
# What session class to use (Class object)
|
|
99
106
|
singleton_attr_writer :session_class
|
data/lib/strelka/authprovider.rb
CHANGED
|
@@ -40,13 +40,16 @@ require 'strelka/mixins'
|
|
|
40
40
|
#
|
|
41
41
|
#
|
|
42
42
|
class Strelka::AuthProvider
|
|
43
|
-
extend
|
|
43
|
+
extend Loggability,
|
|
44
|
+
Strelka::Delegation
|
|
44
45
|
include PluginFactory,
|
|
45
|
-
Strelka::Loggable,
|
|
46
46
|
Strelka::Constants,
|
|
47
47
|
Strelka::AbstractClass,
|
|
48
48
|
Strelka::ResponseHelpers
|
|
49
49
|
|
|
50
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
51
|
+
log_to :strelka
|
|
52
|
+
|
|
50
53
|
|
|
51
54
|
### PluginFactory API -- return the Array of directories to search for concrete
|
|
52
55
|
### AuthProvider classes.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# -*- ruby -*-
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
|
|
4
|
+
require 'loggability'
|
|
4
5
|
require 'configurability'
|
|
5
6
|
|
|
6
7
|
require 'strelka' unless defined?( Strelka )
|
|
@@ -30,10 +31,10 @@ require 'strelka/mixins'
|
|
|
30
31
|
# kmurgen: "MZj9+VhZ8C9+aJhmwp+kWBL76Vs="
|
|
31
32
|
#
|
|
32
33
|
class Strelka::AuthProvider::Basic < Strelka::AuthProvider
|
|
33
|
-
extend
|
|
34
|
+
extend Loggability,
|
|
35
|
+
Configurability,
|
|
34
36
|
Strelka::MethodUtilities
|
|
35
|
-
include Strelka::Constants
|
|
36
|
-
Strelka::Loggable
|
|
37
|
+
include Strelka::Constants
|
|
37
38
|
|
|
38
39
|
# Configurability API - set the section of the config
|
|
39
40
|
config_key :auth
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
|
|
4
4
|
require 'ipaddr'
|
|
5
|
+
require 'loggability'
|
|
5
6
|
require 'configurability'
|
|
6
7
|
|
|
7
8
|
require 'strelka' unless defined?( Strelka )
|
|
@@ -19,12 +20,16 @@ require 'strelka/mixins'
|
|
|
19
20
|
# - 127.0.0.0/8
|
|
20
21
|
# - 10.5.3.0/22
|
|
21
22
|
class Strelka::AuthProvider::HostAccess < Strelka::AuthProvider
|
|
23
|
+
extend Loggability
|
|
22
24
|
include Configurability,
|
|
23
25
|
Strelka::Constants,
|
|
24
|
-
Strelka::Loggable,
|
|
25
26
|
Strelka::MethodUtilities
|
|
26
27
|
|
|
27
28
|
|
|
29
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
30
|
+
log_to :strelka
|
|
31
|
+
|
|
32
|
+
|
|
28
33
|
# The default list of netblocks to allow
|
|
29
34
|
DEFAULT_ALLOWED_NETBLOCKS = %w[127.0.0.0/8]
|
|
30
35
|
|
data/lib/strelka/cookie.rb
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
require 'date'
|
|
6
6
|
require 'time'
|
|
7
7
|
require 'uri'
|
|
8
|
+
require 'loggability'
|
|
8
9
|
|
|
9
10
|
require 'strelka' unless defined?( Strelka )
|
|
10
11
|
require 'strelka/mixins'
|
|
@@ -21,7 +22,11 @@ require 'strelka/mixins'
|
|
|
21
22
|
# reserved.
|
|
22
23
|
#
|
|
23
24
|
class Strelka::Cookie
|
|
24
|
-
|
|
25
|
+
extend Loggability
|
|
26
|
+
|
|
27
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
28
|
+
log_to :strelka
|
|
29
|
+
|
|
25
30
|
|
|
26
31
|
# The format of the date field
|
|
27
32
|
COOKIE_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
|
data/lib/strelka/httprequest.rb
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
require 'yajl'
|
|
6
6
|
require 'yaml'
|
|
7
7
|
require 'uri'
|
|
8
|
+
require 'loggability'
|
|
8
9
|
|
|
9
10
|
require 'mongrel2/httprequest'
|
|
10
11
|
require 'strelka' unless defined?( Strelka )
|
|
@@ -14,10 +15,13 @@ require 'strelka/mixins'
|
|
|
14
15
|
|
|
15
16
|
# An HTTP request class.
|
|
16
17
|
class Strelka::HTTPRequest < Mongrel2::HTTPRequest
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
extend Loggability
|
|
19
|
+
include Strelka::Constants,
|
|
19
20
|
Strelka::ResponseHelpers,
|
|
20
|
-
|
|
21
|
+
Strelka::DataUtilities
|
|
22
|
+
|
|
23
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
24
|
+
log_to :strelka
|
|
21
25
|
|
|
22
26
|
# Set Mongrel2 to use Strelka's request class for HTTP requests
|
|
23
27
|
register_request_type( self, *HTTP::RFC2616_VERBS )
|
|
@@ -152,6 +156,13 @@ class Strelka::HTTPRequest < Mongrel2::HTTPRequest
|
|
|
152
156
|
end
|
|
153
157
|
|
|
154
158
|
|
|
159
|
+
### A convenience method for redirecting a request to another URI.
|
|
160
|
+
def redirect( uri, perm=false )
|
|
161
|
+
code = perm ? HTTP::MOVED_PERMANENTLY : HTTP::MOVED_TEMPORARILY
|
|
162
|
+
finish_with( code, "redirect from #{self.uri.path} to #{uri}", :location => uri )
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
|
|
155
166
|
#########
|
|
156
167
|
protected
|
|
157
168
|
#########
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
# encoding: utf-8
|
|
4
4
|
|
|
5
|
+
require 'loggability'
|
|
5
6
|
require 'strelka/mixins'
|
|
6
7
|
require 'strelka/httprequest'
|
|
7
8
|
|
|
@@ -49,11 +50,15 @@ class Strelka::HTTPRequest
|
|
|
49
50
|
# * Mahlon E. Smith <mahlon@martini.nu>
|
|
50
51
|
#
|
|
51
52
|
class AcceptParam
|
|
53
|
+
extend Loggability
|
|
52
54
|
include Comparable,
|
|
53
|
-
Strelka::Loggable,
|
|
54
55
|
Strelka::AbstractClass
|
|
55
56
|
|
|
56
57
|
|
|
58
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
59
|
+
log_to :strelka
|
|
60
|
+
|
|
61
|
+
|
|
57
62
|
# The default quality value (weight) if none is specified
|
|
58
63
|
Q_DEFAULT = 1.0
|
|
59
64
|
|
|
@@ -61,6 +61,14 @@ module Strelka::HTTPRequest::Session
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
|
|
64
|
+
### Purge the request's session from the session store.
|
|
65
|
+
def destroy_session
|
|
66
|
+
self.log.debug "Removing session id %s" % [ self.session.session_id ]
|
|
67
|
+
Strelka::App::Sessions.session_class.delete_session_data( self.session.session_id )
|
|
68
|
+
@session = nil
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
|
|
64
72
|
### Set the request's session object.
|
|
65
73
|
def session=( new_session )
|
|
66
74
|
new_session.namespace = self.session_namespace
|
data/lib/strelka/httpresponse.rb
CHANGED
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
# encoding: utf-8
|
|
4
4
|
|
|
5
|
+
require 'loggability'
|
|
5
6
|
require 'mongrel2/httpresponse'
|
|
6
7
|
require 'strelka' unless defined?( Strelka )
|
|
7
8
|
require 'strelka/cookieset'
|
|
8
9
|
|
|
9
10
|
# An HTTP response class.
|
|
10
11
|
class Strelka::HTTPResponse < Mongrel2::HTTPResponse
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
extend Loggability
|
|
13
|
+
include Strelka::Constants,
|
|
14
|
+
Strelka::DataUtilities
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
18
|
+
log_to :strelka
|
|
14
19
|
|
|
15
20
|
|
|
16
21
|
# Pattern for matching a 'charset' parameter in a media-type string, such as the
|
data/lib/strelka/mixins.rb
CHANGED
|
@@ -2,90 +2,12 @@
|
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
# encoding: utf-8
|
|
4
4
|
|
|
5
|
-
require 'logger'
|
|
6
|
-
|
|
7
5
|
require 'strelka' unless defined?( Strelka )
|
|
8
6
|
require 'strelka/constants'
|
|
9
7
|
|
|
10
8
|
|
|
11
9
|
module Strelka
|
|
12
10
|
|
|
13
|
-
# Add logging to a Strelka class. Including classes get #log and
|
|
14
|
-
# #log_debug methods.
|
|
15
|
-
#
|
|
16
|
-
# class MyClass
|
|
17
|
-
# include Inversion::Loggable
|
|
18
|
-
#
|
|
19
|
-
# def a_method
|
|
20
|
-
# self.log.debug "Doing a_method stuff..."
|
|
21
|
-
# end
|
|
22
|
-
# end
|
|
23
|
-
#
|
|
24
|
-
module Loggable
|
|
25
|
-
|
|
26
|
-
# A logging proxy class that wraps calls to the logger into calls that include
|
|
27
|
-
# the name of the calling class.
|
|
28
|
-
class ClassNameProxy
|
|
29
|
-
|
|
30
|
-
### Create a new proxy for the given +klass+.
|
|
31
|
-
def initialize( klass, force_debug=false )
|
|
32
|
-
@classname = klass.name
|
|
33
|
-
@force_debug = force_debug
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
### Delegate debug messages to the global logger with the appropriate class name.
|
|
37
|
-
def debug( msg=nil, &block )
|
|
38
|
-
Strelka.logger.add( Logger::DEBUG, msg, @classname, &block )
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
### Delegate info messages to the global logger with the appropriate class name.
|
|
42
|
-
def info( msg=nil, &block )
|
|
43
|
-
return self.debug( msg, &block ) if @force_debug
|
|
44
|
-
Strelka.logger.add( Logger::INFO, msg, @classname, &block )
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
### Delegate warn messages to the global logger with the appropriate class name.
|
|
48
|
-
def warn( msg=nil, &block )
|
|
49
|
-
return self.debug( msg, &block ) if @force_debug
|
|
50
|
-
Strelka.logger.add( Logger::WARN, msg, @classname, &block )
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
### Delegate error messages to the global logger with the appropriate class name.
|
|
54
|
-
def error( msg=nil, &block )
|
|
55
|
-
return self.debug( msg, &block ) if @force_debug
|
|
56
|
-
Strelka.logger.add( Logger::ERROR, msg, @classname, &block )
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
### Delegate fatal messages to the global logger with the appropriate class name.
|
|
60
|
-
def fatal( msg=nil, &block )
|
|
61
|
-
Strelka.logger.add( Logger::FATAL, msg, @classname, &block )
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
end # ClassNameProxy
|
|
65
|
-
|
|
66
|
-
#########
|
|
67
|
-
protected
|
|
68
|
-
#########
|
|
69
|
-
|
|
70
|
-
### Copy constructor -- clear the original's log proxy.
|
|
71
|
-
def initialize_copy( original )
|
|
72
|
-
@log_proxy = @log_debug_proxy = nil
|
|
73
|
-
super
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
### Return the proxied logger.
|
|
77
|
-
def log
|
|
78
|
-
@log_proxy ||= ClassNameProxy.new( self.class )
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
### Return a proxied "debug" logger that ignores other level specification.
|
|
82
|
-
def log_debug
|
|
83
|
-
@log_debug_proxy ||= ClassNameProxy.new( self.class, true )
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
end # module Loggable
|
|
87
|
-
|
|
88
|
-
|
|
89
11
|
# Hides your class's ::new method and adds a +pure_virtual+ method generator for
|
|
90
12
|
# defining API methods. If subclasses of your class don't provide implementations of
|
|
91
13
|
# "pure_virtual" methods, NotImplementedErrors will be raised if they are called.
|
|
@@ -351,6 +273,7 @@ module Strelka
|
|
|
351
273
|
|
|
352
274
|
# A collection of functions for generating responses.
|
|
353
275
|
module ResponseHelpers
|
|
276
|
+
include Strelka::Constants
|
|
354
277
|
|
|
355
278
|
### Abort the current execution and return a response with the specified
|
|
356
279
|
### http_status code immediately. The specified +message+ will be logged,
|
|
@@ -375,9 +298,13 @@ module Strelka
|
|
|
375
298
|
end
|
|
376
299
|
|
|
377
300
|
# Log using the instance logger if possible, else use the global one
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
301
|
+
logmsg = "Finishing with status %d: %s" % [ status_info[:status], status_info[:message] ]
|
|
302
|
+
if status_info[:status] > 399
|
|
303
|
+
self.log.info( logmsg )
|
|
304
|
+
else
|
|
305
|
+
self.log.error( logmsg )
|
|
306
|
+
end
|
|
307
|
+
|
|
381
308
|
|
|
382
309
|
throw :finish, status_info
|
|
383
310
|
end
|
|
@@ -8,6 +8,7 @@ require 'uri'
|
|
|
8
8
|
require 'forwardable'
|
|
9
9
|
require 'date'
|
|
10
10
|
require 'formvalidator'
|
|
11
|
+
require 'loggability'
|
|
11
12
|
|
|
12
13
|
require 'strelka/mixins'
|
|
13
14
|
require 'strelka' unless defined?( Strelka )
|
|
@@ -52,8 +53,12 @@ require 'strelka/app' unless defined?( Strelka::App )
|
|
|
52
53
|
# end
|
|
53
54
|
#
|
|
54
55
|
class Strelka::ParamValidator < ::FormValidator
|
|
55
|
-
extend Forwardable
|
|
56
|
-
|
|
56
|
+
extend Forwardable,
|
|
57
|
+
Loggability
|
|
58
|
+
|
|
59
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
60
|
+
log_to :strelka
|
|
61
|
+
|
|
57
62
|
|
|
58
63
|
# Options that are passed as Symbols to .param
|
|
59
64
|
FLAGS = [ :required, :untaint ]
|
data/lib/strelka/router.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
# encoding: utf-8
|
|
4
4
|
|
|
5
|
+
require 'loggability'
|
|
5
6
|
require 'pluginfactory'
|
|
6
7
|
|
|
7
8
|
require 'strelka' unless defined?( Strelka )
|
|
@@ -23,9 +24,13 @@ require 'strelka/mixins'
|
|
|
23
24
|
# <tt>strelka/router/{something}.rb</tt>, and be sure to override the
|
|
24
25
|
# #add_route and #route_request methods.
|
|
25
26
|
class Strelka::Router
|
|
27
|
+
extend Loggability
|
|
26
28
|
include PluginFactory,
|
|
27
|
-
Strelka::
|
|
28
|
-
|
|
29
|
+
Strelka::AbstractClass
|
|
30
|
+
|
|
31
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
32
|
+
log_to :strelka
|
|
33
|
+
|
|
29
34
|
|
|
30
35
|
### PluginFactory API -- return the Array of directories to search for plugins.
|
|
31
36
|
def self::derivative_dirs
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
# encoding: utf-8
|
|
4
4
|
|
|
5
|
+
require 'loggability'
|
|
6
|
+
|
|
5
7
|
require 'strelka' unless defined?( Strelka )
|
|
6
8
|
require 'strelka/app' unless defined?( Strelka::App )
|
|
7
9
|
require 'strelka/router'
|
|
8
10
|
|
|
9
11
|
# Simple (dumb?) request router for Strelka::App-based applications.
|
|
10
12
|
class Strelka::Router::Default < Strelka::Router
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
extend Loggability
|
|
14
|
+
include Strelka::Constants,
|
|
13
15
|
Strelka::ResponseHelpers
|
|
14
16
|
|
|
15
17
|
### Create a new router that will route requests according to the specified
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
# encoding: utf-8
|
|
4
4
|
|
|
5
|
+
require 'loggability'
|
|
6
|
+
|
|
5
7
|
require 'strelka' unless defined?( Strelka )
|
|
6
8
|
require 'strela/app' unless defined?( Strelka::App )
|
|
7
9
|
|
|
@@ -24,7 +26,11 @@ require 'strelka/router/default'
|
|
|
24
26
|
# end # class MyApp
|
|
25
27
|
#
|
|
26
28
|
class Strelka::Router::Exclusive < Strelka::Router::Default
|
|
27
|
-
|
|
29
|
+
extend Loggability
|
|
30
|
+
|
|
31
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
32
|
+
log_to :strelka
|
|
33
|
+
|
|
28
34
|
|
|
29
35
|
######
|
|
30
36
|
public
|
data/lib/strelka/session.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require 'digest/sha1'
|
|
5
5
|
require 'pluginfactory'
|
|
6
|
+
require 'loggability'
|
|
6
7
|
|
|
7
8
|
require 'strelka' unless defined?( Strelka )
|
|
8
9
|
require 'strelka/mixins'
|
|
@@ -42,9 +43,12 @@ require 'strelka/mixins'
|
|
|
42
43
|
#
|
|
43
44
|
#
|
|
44
45
|
class Strelka::Session
|
|
46
|
+
extend Loggability
|
|
45
47
|
include PluginFactory,
|
|
46
|
-
Strelka::
|
|
47
|
-
|
|
48
|
+
Strelka::AbstractClass
|
|
49
|
+
|
|
50
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
51
|
+
log_to :strelka
|
|
48
52
|
|
|
49
53
|
|
|
50
54
|
### PluginFactory API -- return the Array of directories to search for concrete
|
data/lib/strelka/session/db.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# -*- ruby -*-
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
|
|
4
|
+
require 'loggability'
|
|
4
5
|
require 'securerandom'
|
|
5
6
|
require 'forwardable'
|
|
6
7
|
require 'sequel'
|
|
@@ -14,10 +15,14 @@ require 'strelka/session/default'
|
|
|
14
15
|
# any database that Sequel supports. It defaults to non-persistent, in memory Sqlite.
|
|
15
16
|
#
|
|
16
17
|
class Strelka::Session::Db < Strelka::Session::Default
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
extend Loggability,
|
|
19
|
+
Forwardable,
|
|
19
20
|
Strelka::MethodUtilities
|
|
20
21
|
|
|
22
|
+
# Loggability API -- set up logging under the 'strelka' log host
|
|
23
|
+
log_to :strelka
|
|
24
|
+
|
|
25
|
+
|
|
21
26
|
# Class-instance variables
|
|
22
27
|
@table_name = :sessions
|
|
23
28
|
@db = nil
|
|
@@ -59,7 +64,7 @@ class Strelka::Session::Db < Strelka::Session::Default
|
|
|
59
64
|
@db = options[ :connect ].nil? ?
|
|
60
65
|
Mongrel2::Config.in_memory_db :
|
|
61
66
|
Sequel.connect( options[:connect] )
|
|
62
|
-
@db.logger =
|
|
67
|
+
@db.logger = Loggability[ Mongrel2 ].proxy_for( @db )
|
|
63
68
|
|
|
64
69
|
self.initialize_sessions_table
|
|
65
70
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# -*- ruby -*-
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
|
|
4
|
+
require 'loggability'
|
|
4
5
|
require 'securerandom'
|
|
5
6
|
require 'forwardable'
|
|
6
7
|
|
|
@@ -17,11 +18,11 @@ require 'strelka/mixins'
|
|
|
17
18
|
# The following methods are delegated to the inner Hash via the #namespaced_hash method:
|
|
18
19
|
# #[], #[]=, #delete, #key?
|
|
19
20
|
class Strelka::Session::Default < Strelka::Session
|
|
20
|
-
extend
|
|
21
|
+
extend Loggability,
|
|
22
|
+
Forwardable,
|
|
21
23
|
Strelka::MethodUtilities,
|
|
22
24
|
Strelka::Delegation
|
|
23
|
-
include Strelka::
|
|
24
|
-
Strelka::DataUtilities
|
|
25
|
+
include Strelka::DataUtilities
|
|
25
26
|
|
|
26
27
|
# Default configuration
|
|
27
28
|
DEFAULT_COOKIE_OPTIONS = {
|
data/spec/lib/helpers.rb
CHANGED
|
@@ -83,35 +83,28 @@ module Strelka::SpecHelpers
|
|
|
83
83
|
|
|
84
84
|
### Reset the logging subsystem to its default state.
|
|
85
85
|
def reset_logging
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
Loggability.formatter = nil
|
|
87
|
+
Loggability.output_to( $stderr )
|
|
88
|
+
Loggability.level = :fatal
|
|
88
89
|
end
|
|
89
90
|
|
|
90
91
|
|
|
91
92
|
### Alter the output of the default log formatter to be pretty in SpecMate output
|
|
92
93
|
def setup_logging( level=Logger::FATAL )
|
|
93
94
|
|
|
94
|
-
# Turn symbol-style level config into Logger's expected Fixnum level
|
|
95
|
-
if Strelka::Logging::LOG_LEVELS.key?( level.to_s )
|
|
96
|
-
level = Strelka::Logging::LOG_LEVELS[ level.to_s ]
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
logger = Logger.new( $stderr )
|
|
100
|
-
Strelka.logger = logger
|
|
101
|
-
Strelka.logger.level = level
|
|
102
|
-
Mongrel2.logger.level = level
|
|
103
|
-
|
|
104
95
|
# Only do this when executing from a spec in TextMate
|
|
105
96
|
if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
97
|
+
logarray = []
|
|
98
|
+
Thread.current['logger-output'] = logarray
|
|
99
|
+
Loggability.output_to( logarray )
|
|
100
|
+
Loggability.format_as( :html )
|
|
101
|
+
Loggability.level = :debug
|
|
102
|
+
else
|
|
103
|
+
Loggability.level = level
|
|
112
104
|
end
|
|
113
105
|
end
|
|
114
106
|
|
|
107
|
+
|
|
115
108
|
### Set up a Mongrel2 configuration database according to the specified +dbspec+.
|
|
116
109
|
### Set up a Mongrel2 configuration database in memory.
|
|
117
110
|
def setup_config_db
|
|
@@ -110,13 +110,18 @@ describe Strelka::HTTPRequest::Session, "-extended request" do
|
|
|
110
110
|
context "and a corresponding entry in the database" do
|
|
111
111
|
|
|
112
112
|
before( :each ) do
|
|
113
|
-
|
|
113
|
+
@req.session[ :test ] = true
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
it "knows that it has a session" do
|
|
117
117
|
@req.should have_session()
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
+
it "can purge the session from the database" do
|
|
121
|
+
@req.should have_session()
|
|
122
|
+
@req.destroy_session
|
|
123
|
+
@req.should_not have_session()
|
|
124
|
+
end
|
|
120
125
|
end
|
|
121
126
|
|
|
122
127
|
end
|
|
@@ -65,6 +65,16 @@ describe Strelka::HTTPRequest do
|
|
|
65
65
|
@req.notes[:routing][:route].should be_a( Hash )
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
it "can redirect the request to a different URI" do
|
|
69
|
+
uri = 'http://www.google.com/'
|
|
70
|
+
expect {
|
|
71
|
+
@req.redirect( uri )
|
|
72
|
+
}.to finish_with( HTTP::MOVED_TEMPORARILY, nil, :location => uri )
|
|
73
|
+
|
|
74
|
+
expect {
|
|
75
|
+
@req.redirect( uri, true )
|
|
76
|
+
}.to finish_with( HTTP::MOVED_PERMANENTLY, nil, :location => uri )
|
|
77
|
+
end
|
|
68
78
|
end
|
|
69
79
|
|
|
70
80
|
|
data/spec/strelka/mixins_spec.rb
CHANGED
|
@@ -21,40 +21,6 @@ require 'strelka/mixins'
|
|
|
21
21
|
describe Strelka, "mixins" do
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
describe Strelka::Loggable do
|
|
25
|
-
before(:each) do
|
|
26
|
-
@logfile = StringIO.new('')
|
|
27
|
-
Strelka.logger = Logger.new( @logfile )
|
|
28
|
-
|
|
29
|
-
@test_class = Class.new do
|
|
30
|
-
include Strelka::Loggable
|
|
31
|
-
|
|
32
|
-
def log_test_message( level, msg )
|
|
33
|
-
self.log.send( level, msg )
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def logdebug_test_message( msg )
|
|
37
|
-
self.log_debug.debug( msg )
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
@obj = @test_class.new
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
it "is able to output to the log via its #log method" do
|
|
45
|
-
@obj.log_test_message( :debug, "debugging message" )
|
|
46
|
-
@logfile.rewind
|
|
47
|
-
@logfile.read.should =~ /debugging message/
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "is able to output to the log via its #log_debug method" do
|
|
51
|
-
@obj.logdebug_test_message( "sexydrownwatch" )
|
|
52
|
-
@logfile.rewind
|
|
53
|
-
@logfile.read.should =~ /sexydrownwatch/
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
|
|
58
24
|
describe Strelka::AbstractClass do
|
|
59
25
|
|
|
60
26
|
context "mixed into a class" do
|
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.
|
|
4
|
+
version: 0.0.1.pre.224
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
|
36
36
|
YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
|
|
37
37
|
Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
|
|
38
38
|
cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
|
39
|
-
date: 2012-05-
|
|
39
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
|
40
40
|
dependencies:
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: trollop
|
|
@@ -182,6 +182,22 @@ dependencies:
|
|
|
182
182
|
- - ~>
|
|
183
183
|
- !ruby/object:Gem::Version
|
|
184
184
|
version: '1.0'
|
|
185
|
+
- !ruby/object:Gem::Dependency
|
|
186
|
+
name: loggability
|
|
187
|
+
requirement: !ruby/object:Gem::Requirement
|
|
188
|
+
none: false
|
|
189
|
+
requirements:
|
|
190
|
+
- - ~>
|
|
191
|
+
- !ruby/object:Gem::Version
|
|
192
|
+
version: '0.0'
|
|
193
|
+
type: :runtime
|
|
194
|
+
prerelease: false
|
|
195
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
196
|
+
none: false
|
|
197
|
+
requirements:
|
|
198
|
+
- - ~>
|
|
199
|
+
- !ruby/object:Gem::Version
|
|
200
|
+
version: '0.0'
|
|
185
201
|
- !ruby/object:Gem::Dependency
|
|
186
202
|
name: hoe-mercurial
|
|
187
203
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
|
Binary file
|