strelka 0.0.1.pre.187 → 0.0.1.pre.193

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +94 -26
  3. data/Manifest.txt +4 -2
  4. data/examples/apps/ws-echo +17 -0
  5. data/lib/strelka/app.rb +26 -24
  6. data/lib/strelka/app/auth.rb +2 -1
  7. data/lib/strelka/app/errors.rb +1 -1
  8. data/lib/strelka/app/filters.rb +1 -1
  9. data/lib/strelka/app/negotiation.rb +1 -1
  10. data/lib/strelka/app/parameters.rb +2 -2
  11. data/lib/strelka/app/restresources.rb +1 -1
  12. data/lib/strelka/app/routing.rb +3 -2
  13. data/lib/strelka/app/sessions.rb +3 -3
  14. data/lib/strelka/app/templating.rb +3 -3
  15. data/lib/strelka/authprovider.rb +2 -10
  16. data/lib/strelka/behavior/plugin.rb +3 -3
  17. data/lib/strelka/httprequest.rb +5 -2
  18. data/lib/strelka/httprequest/session.rb +3 -2
  19. data/lib/strelka/httpresponse/session.rb +8 -9
  20. data/lib/strelka/mixins.rb +15 -0
  21. data/lib/strelka/plugins.rb +257 -0
  22. data/lib/strelka/router/default.rb +27 -2
  23. data/lib/strelka/session.rb +20 -2
  24. data/lib/strelka/session/db.rb +20 -10
  25. data/lib/strelka/session/default.rb +41 -18
  26. data/spec/lib/helpers.rb +1 -1
  27. data/spec/strelka/app/auth_spec.rb +1 -1
  28. data/spec/strelka/app/errors_spec.rb +1 -1
  29. data/spec/strelka/app/filters_spec.rb +1 -1
  30. data/spec/strelka/app/negotiation_spec.rb +1 -1
  31. data/spec/strelka/app/parameters_spec.rb +1 -1
  32. data/spec/strelka/app/restresources_spec.rb +1 -1
  33. data/spec/strelka/app/routing_spec.rb +4 -1
  34. data/spec/strelka/app/sessions_spec.rb +63 -17
  35. data/spec/strelka/app/templating_spec.rb +1 -1
  36. data/spec/strelka/app_spec.rb +13 -5
  37. data/spec/strelka/httprequest/session_spec.rb +44 -23
  38. data/spec/strelka/httprequest_spec.rb +21 -0
  39. data/spec/strelka/httpresponse/session_spec.rb +143 -0
  40. data/spec/strelka/{app/plugins_spec.rb → plugins_spec.rb} +64 -53
  41. data/spec/strelka/router/default_spec.rb +15 -0
  42. data/spec/strelka/router/exclusive_spec.rb +14 -0
  43. data/spec/strelka/session/db_spec.rb +11 -0
  44. data/spec/strelka/session/default_spec.rb +10 -2
  45. metadata +119 -37
  46. metadata.gz.sig +0 -0
  47. data/lib/strelka/app/plugins.rb +0 -284
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,3 +1,75 @@
1
+ 2012-04-18 Michael Granger <ged@FaerieMUD.org>
2
+
3
+ * examples/apps/ws-echo, experiments/reflective-module.rb,
4
+ lib/strelka/app.rb, lib/strelka/app/auth.rb,
5
+ lib/strelka/app/errors.rb, lib/strelka/app/filters.rb,
6
+ lib/strelka/app/negotiation.rb, lib/strelka/app/parameters.rb,
7
+ lib/strelka/app/plugins.rb, lib/strelka/app/restresources.rb,
8
+ lib/strelka/app/routing.rb, lib/strelka/app/sessions.rb,
9
+ lib/strelka/app/templating.rb, lib/strelka/behavior/plugin.rb,
10
+ lib/strelka/plugins.rb, spec/strelka/app/auth_spec.rb,
11
+ spec/strelka/app/errors_spec.rb, spec/strelka/app/filters_spec.rb,
12
+ spec/strelka/app/negotiation_spec.rb,
13
+ spec/strelka/app/parameters_spec.rb,
14
+ spec/strelka/app/plugins_spec.rb,
15
+ spec/strelka/app/restresources_spec.rb,
16
+ spec/strelka/app/routing_spec.rb, spec/strelka/app/sessions_spec.rb,
17
+ spec/strelka/app/templating_spec.rb, spec/strelka/app_spec.rb,
18
+ spec/strelka/plugins_spec.rb:
19
+ Generalize the plugin system.
20
+
21
+ This change pulls the plugin system out of App and makes it a
22
+ generic system that can extend any class with a plugin system. This
23
+ was done in anticipation of a new WebSocket server class, which will
24
+ also have App-style plugins, but with a different API, and loaded
25
+ from a different place in the filesystem.
26
+
27
+ This change requires code changes to plugins and the classes that
28
+ are extended by them:
29
+
30
+ * Strelka::App::Plugin is now Strelka::Plugin
31
+ * Strelka::App::Plugins is now Strelka::PluginLoader
32
+ [ea4c4358a943] [tip]
33
+
34
+ 2012-04-16 Mahlon E. Smith <mahlon@martini.nu>
35
+
36
+ * lib/strelka/app/sessions.rb, lib/strelka/httprequest/session.rb,
37
+ lib/strelka/httpresponse/session.rb, lib/strelka/session.rb,
38
+ lib/strelka/session/db.rb, lib/strelka/session/default.rb,
39
+ manual/src/starting.page, spec/lib/helpers.rb,
40
+ spec/strelka/app/sessions_spec.rb,
41
+ spec/strelka/httprequest/session_spec.rb,
42
+ spec/strelka/httpresponse/session_spec.rb,
43
+ spec/strelka/session/db_spec.rb,
44
+ spec/strelka/session/default_spec.rb:
45
+ Make Request#session? ask the session store if a session exists.
46
+ [a351bc3b9528]
47
+
48
+ * lib/strelka/httprequest.rb, spec/strelka/httprequest_spec.rb,
49
+ spec/strelka/router/default_spec.rb:
50
+ Explicitly handle nil content-types during form data parsing.
51
+ [59b791e4bfbe]
52
+
53
+ * lib/strelka/app.rb, lib/strelka/authprovider.rb,
54
+ lib/strelka/mixins.rb, lib/strelka/router/default.rb,
55
+ spec/strelka/router/default_spec.rb,
56
+ spec/strelka/router/exclusive_spec.rb:
57
+ Return an HTTP::METHOD_NOT_ALLOWED if the request route is valid,
58
+ but the method is not.
59
+ [5d62cb4be772]
60
+
61
+ 2012-04-11 Michael Granger <ged@FaerieMUD.org>
62
+
63
+ * lib/strelka/app/routing.rb, lib/strelka/app/templating.rb,
64
+ spec/strelka/app/routing_spec.rb:
65
+ Add Router#routerclass to subclasses. nil guard for
66
+ layout_templates.
67
+ [279f2399ad4a] [github/master]
68
+
69
+ * Rakefile:
70
+ Remove outdated Rakefile cruft.
71
+ [02441af05e37]
72
+
1
73
  2012-04-11 Mahlon E. Smith <mahlon@martini.nu>
2
74
 
3
75
  * lib/strelka/app/auth.rb, lib/strelka/app/errors.rb,
@@ -16,7 +88,7 @@
16
88
  Currently, this is done manually by defining an inherited hook in
17
89
  each plugin's ClassMethods, but we'll likely try to find some way to
18
90
  automate it or at least refacter it into a declarative or two.
19
- [4217deb1952c] [tip]
91
+ [4217deb1952c]
20
92
 
21
93
  2012-04-11 Michael Granger <ged@FaerieMUD.org>
22
94
 
@@ -40,18 +112,16 @@
40
112
  * Merging with ssh://hg@deveiate.org/Strelka@8f1c27819e70
41
113
  [5fcd76455aad]
42
114
 
115
+ * Manifest.txt:
116
+ Updating the manifest
117
+ [35165b3d01cc]
118
+
43
119
  2012-04-11 Mahlon E. Smith <mahlon@martini.nu>
44
120
 
45
121
  * lib/strelka/session/default.rb:
46
122
  Use the built-in securerandom method for obtaining a hex value.
47
123
  [8f1c27819e70]
48
124
 
49
- 2012-04-11 Michael Granger <ged@FaerieMUD.org>
50
-
51
- * Manifest.txt:
52
- Updating the manifest
53
- [35165b3d01cc]
54
-
55
125
  2012-04-10 Michael Granger <ged@FaerieMUD.org>
56
126
 
57
127
  * lib/strelka/app/auth.rb, lib/strelka/app/parameters.rb,
@@ -62,7 +132,7 @@
62
132
  spec/strelka/paramvalidator_spec.rb:
63
133
  Rework the paramvalidator and parameters plugin to allow per-request
64
134
  overrides
65
- [e7393474988b] [github/master]
135
+ [e7393474988b]
66
136
 
67
137
  * bin/leash, examples/apps/auth-demo, examples/apps/auth-demo2,
68
138
  examples/apps/sessions-demo, examples/auth-demo.rb, examples/auth-
@@ -122,6 +192,22 @@
122
192
  Add the ChangeLog to the ignorefile
123
193
  [cc8c30d38652]
124
194
 
195
+ * lib/strelka/app/templating.rb:
196
+ Add API docs to the :templating plugin module
197
+ [3c160d996320]
198
+
199
+ * README.rdoc:
200
+ Add more URLs
201
+ [060962556bd1]
202
+
203
+ * Rakefile:
204
+ Oops. Fix typo
205
+ [5a8aa207860b]
206
+
207
+ * .rvm.gems, Rakefile:
208
+ Update dependencies
209
+ [787e523777d1]
210
+
125
211
  2012-04-06 Mahlon E. Smith <mahlon@martini.nu>
126
212
 
127
213
  * lib/strelka/app/sessions.rb, lib/strelka/cookie.rb,
@@ -139,24 +225,6 @@
139
225
  Add a persistent DB session store, using sequel.
140
226
  [99f3c3f5d6ca]
141
227
 
142
- 2012-04-06 Michael Granger <ged@FaerieMUD.org>
143
-
144
- * lib/strelka/app/templating.rb:
145
- Add API docs to the :templating plugin module
146
- [3c160d996320]
147
-
148
- * README.rdoc:
149
- Add more URLs
150
- [060962556bd1]
151
-
152
- * Rakefile:
153
- Oops. Fix typo
154
- [5a8aa207860b]
155
-
156
- * .rvm.gems, Rakefile:
157
- Update dependencies
158
- [787e523777d1]
159
-
160
228
  2012-04-04 Michael Granger <ged@FaerieMUD.org>
161
229
 
162
230
  * manual/src/tutorial.page:
data/Manifest.txt CHANGED
@@ -19,6 +19,7 @@ data/strelka/apps/hello-world
19
19
  examples/apps/auth-demo
20
20
  examples/apps/auth-demo2
21
21
  examples/apps/sessions-demo
22
+ examples/apps/ws-echo
22
23
  examples/config.yml
23
24
  examples/gen-config.rb
24
25
  examples/static/examples.css
@@ -33,7 +34,6 @@ lib/strelka/app/errors.rb
33
34
  lib/strelka/app/filters.rb
34
35
  lib/strelka/app/negotiation.rb
35
36
  lib/strelka/app/parameters.rb
36
- lib/strelka/app/plugins.rb
37
37
  lib/strelka/app/restresources.rb
38
38
  lib/strelka/app/routing.rb
39
39
  lib/strelka/app/sessions.rb
@@ -57,6 +57,7 @@ lib/strelka/httpresponse/session.rb
57
57
  lib/strelka/logging.rb
58
58
  lib/strelka/mixins.rb
59
59
  lib/strelka/paramvalidator.rb
60
+ lib/strelka/plugins.rb
60
61
  lib/strelka/router.rb
61
62
  lib/strelka/router/default.rb
62
63
  lib/strelka/router/exclusive.rb
@@ -73,7 +74,6 @@ spec/strelka/app/errors_spec.rb
73
74
  spec/strelka/app/filters_spec.rb
74
75
  spec/strelka/app/negotiation_spec.rb
75
76
  spec/strelka/app/parameters_spec.rb
76
- spec/strelka/app/plugins_spec.rb
77
77
  spec/strelka/app/restresources_spec.rb
78
78
  spec/strelka/app/routing_spec.rb
79
79
  spec/strelka/app/sessions_spec.rb
@@ -91,10 +91,12 @@ spec/strelka/httprequest/negotiation_spec.rb
91
91
  spec/strelka/httprequest/session_spec.rb
92
92
  spec/strelka/httprequest_spec.rb
93
93
  spec/strelka/httpresponse/negotiation_spec.rb
94
+ spec/strelka/httpresponse/session_spec.rb
94
95
  spec/strelka/httpresponse_spec.rb
95
96
  spec/strelka/logging_spec.rb
96
97
  spec/strelka/mixins_spec.rb
97
98
  spec/strelka/paramvalidator_spec.rb
99
+ spec/strelka/plugins_spec.rb
98
100
  spec/strelka/router/default_spec.rb
99
101
  spec/strelka/router/exclusive_spec.rb
100
102
  spec/strelka/router_spec.rb
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ #encoding: utf-8
4
+
5
+ require 'strelka'
6
+
7
+ # A demo of the WebSocketServer -- this does the same thing as the Mongrel2
8
+ # echo server, but uses the Strelka WebSocket class.
9
+ class WebSocketEchoServer < Strelka::WebSocketServer
10
+
11
+ # Use the heartbeat plugin
12
+ plugins :heartbeat
13
+
14
+
15
+
16
+
17
+ end
data/lib/strelka/app.rb CHANGED
@@ -7,17 +7,16 @@ require 'rubygems' # For the Rubygems API
7
7
  require 'mongrel2/handler'
8
8
  require 'strelka' unless defined?( Strelka )
9
9
  require 'strelka/mixins'
10
+ require 'strelka/plugins'
10
11
 
11
12
 
12
13
  # The application base class.
13
14
  class Strelka::App < Mongrel2::Handler
14
- extend Strelka::MethodUtilities
15
+ extend Strelka::MethodUtilities,
16
+ Strelka::PluginLoader
15
17
  include Strelka::Loggable,
16
- Strelka::Constants
17
-
18
- # Load the plugin system
19
- require 'strelka/app/plugins'
20
- include Strelka::App::Plugins
18
+ Strelka::Constants,
19
+ Strelka::ResponseHelpers
21
20
 
22
21
 
23
22
  # Glob for matching Strelka apps relative to a gem's data directory
@@ -238,22 +237,35 @@ class Strelka::App < Mongrel2::Handler
238
237
  ### wish to modify or replace the request before the request cycle is
239
238
  ### started.
240
239
  def fixup_request( request )
241
- self.log.debug "Fixing up request: %p" % [ request ]
242
- request = super
243
- self.log.debug " after fixup: %p" % [ request ]
244
-
245
240
  return request
246
241
  end
247
242
 
248
243
 
249
244
  ### Handle the request and return a +response+. This is the main extension-point
250
245
  ### for the plugin system. Without being overridden or extended by plugins, this
251
- ### method just returns the default Mongrel2::HTTPRequest#response.
246
+ ### method just returns the default Mongrel2::HTTPRequest#response. If you override
247
+ ### this directly in your App subclass, you'll need to +super+ with a block if you
248
+ ### wish the plugins to run on the request, then do whatever it is you want in the
249
+ ### block and return the response, which the plugins will again have an opportunity
250
+ ### to modify.
251
+ ###
252
+ ### Example:
253
+ ###
254
+ ### class MyApp < Strelka::App
255
+ ### def handle_request( request )
256
+ ### super do |req|
257
+ ### res = req.response
258
+ ### res.content_type = 'text/plain'
259
+ ### res.puts "Hello!"
260
+ ### return res
261
+ ### end
262
+ ### end
263
+ ### end
252
264
  def handle_request( request, &block )
253
265
  if block
254
- return super( request, &block )
266
+ return block.call( request )
255
267
  else
256
- return super( request ) {|r| r.response }
268
+ return request.response
257
269
  end
258
270
  end
259
271
 
@@ -269,7 +281,7 @@ class Strelka::App < Mongrel2::Handler
269
281
  response.request && response.request.verb == :HEAD
270
282
  self.log.debug " after fixup: %p" % [ response ]
271
283
 
272
- return super
284
+ return response
273
285
  end
274
286
 
275
287
 
@@ -309,16 +321,6 @@ class Strelka::App < Mongrel2::Handler
309
321
  end
310
322
 
311
323
 
312
- ### Abort the current execution and return a response with the specified
313
- ### http_status code immediately. The specified +message+ will be logged,
314
- ### and will be included in any message that is returned as part of the
315
- ### response. The +headers+ hash will be used to set response headers.
316
- def finish_with( http_status, message, headers={} )
317
- status_info = { :status => http_status, :message => message, :headers => headers }
318
- throw :finish, status_info
319
- end
320
-
321
-
322
324
  ### Create a response to specified +request+ based on the specified +status_code+
323
325
  ### and +message+.
324
326
  ### :TODO: Document and test the :content_type status_info field.
@@ -4,6 +4,7 @@
4
4
 
5
5
  require 'strelka' unless defined?( Strelka )
6
6
  require 'strelka/app' unless defined?( Strelka::App )
7
+ require 'strelka/plugins'
7
8
 
8
9
  require 'strelka/httprequest/auth'
9
10
  require 'strelka/authprovider'
@@ -235,7 +236,7 @@ require 'strelka/authprovider'
235
236
  # end
236
237
  #
237
238
  module Strelka::App::Auth
238
- extend Strelka::App::Plugin,
239
+ extend Strelka::Plugin,
239
240
  Strelka::MethodUtilities,
240
241
  Configurability
241
242
  include Strelka::Loggable,
@@ -36,7 +36,7 @@ require 'strelka/app' unless defined?( Strelka::App )
36
36
  #
37
37
  # See the documentation for ClassMethods.on_status for more details.
38
38
  module Strelka::App::Errors
39
- extend Strelka::App::Plugin
39
+ extend Strelka::Plugin
40
40
 
41
41
  DEFAULT_HANDLER_STATUS_RANGE = 400..599
42
42
 
@@ -8,7 +8,7 @@ require 'strelka/app' unless defined?( Strelka::App )
8
8
 
9
9
  # Request/response filters plugin for Strelka::App.
10
10
  module Strelka::App::Filters
11
- extend Strelka::App::Plugin
11
+ extend Strelka::Plugin
12
12
 
13
13
  run_before :routing, :templating
14
14
 
@@ -40,7 +40,7 @@ require 'strelka/httpresponse/negotiation'
40
40
  #
41
41
  module Strelka::App::Negotiation
42
42
  include Strelka::Constants
43
- extend Strelka::App::Plugin
43
+ extend Strelka::Plugin
44
44
 
45
45
  run_before :routing
46
46
  run_after :filters, :templating, :parameters
@@ -4,7 +4,7 @@
4
4
 
5
5
  require 'strelka' unless defined?( Strelka )
6
6
  require 'strelka/app' unless defined?( Strelka::App )
7
- require 'strelka/app/plugins'
7
+ require 'strelka/plugins'
8
8
  require 'strelka/paramvalidator'
9
9
 
10
10
 
@@ -36,7 +36,7 @@ require 'strelka/paramvalidator'
36
36
  # end # class UserManager
37
37
  #
38
38
  module Strelka::App::Parameters
39
- extend Strelka::App::Plugin
39
+ extend Strelka::Plugin
40
40
 
41
41
  run_before :routing
42
42
  run_after :filters
@@ -51,7 +51,7 @@ require 'strelka/app' unless defined?( Strelka::App )
51
51
  # isn't clearly specified in the RFC (DELETE /resource)
52
52
  # * Sequel plugin for adding links to serialized representations
53
53
  module Strelka::App::RestResources
54
- extend Strelka::App::Plugin
54
+ extend Strelka::Plugin
55
55
 
56
56
  # Resource route option defaults
57
57
  DEFAULTS = {
@@ -7,7 +7,7 @@ require 'strelka/app' unless defined?( Strelka::App )
7
7
 
8
8
  require 'strelka/router'
9
9
  require 'strelka/exceptions'
10
- require 'strelka/app/plugins'
10
+ require 'strelka/plugins'
11
11
 
12
12
  # Sinatra-ish routing logic for Strelka::Apps
13
13
  #
@@ -80,7 +80,7 @@ require 'strelka/app/plugins'
80
80
  # routing strategies.
81
81
  #
82
82
  module Strelka::App::Routing
83
- extend Strelka::App::Plugin
83
+ extend Strelka::Plugin
84
84
  include Strelka::Loggable,
85
85
  Strelka::Constants
86
86
 
@@ -232,6 +232,7 @@ module Strelka::App::Routing
232
232
  ### Inheritance hook -- inheriting classes inherit their parents' routes table.
233
233
  def inherited( subclass )
234
234
  super
235
+ subclass.instance_variable_set( :@routerclass, self.routerclass )
235
236
  subclass.instance_variable_set( :@routes, self.routes.dup )
236
237
  end
237
238
 
@@ -5,7 +5,7 @@ require 'strelka/app' unless defined?( Strelka::App )
5
5
 
6
6
  require 'strelka/mixins'
7
7
  require 'strelka/exceptions'
8
- require 'strelka/app/plugins'
8
+ require 'strelka/plugins'
9
9
 
10
10
  require 'strelka/httprequest/session'
11
11
  require 'strelka/httpresponse/session'
@@ -78,7 +78,7 @@ require 'strelka/httpresponse/session'
78
78
  # is passed to the session class's ::configure method (if it has one).
79
79
  #
80
80
  module Strelka::App::Sessions
81
- extend Strelka::App::Plugin,
81
+ extend Strelka::Plugin,
82
82
  Strelka::MethodUtilities,
83
83
  Configurability
84
84
  include Strelka::Loggable,
@@ -134,7 +134,7 @@ module Strelka::App::Sessions
134
134
 
135
135
  ### Configurability API -- set up session type and options with values from
136
136
  ### the +config+.
137
- def self::configure( config )
137
+ def self::configure( config=nil )
138
138
  options = DEFAULT_OPTIONS.dup
139
139
 
140
140
  # Figure out which session class is going to be used, or choose a default one