strelka 0.0.1pre4 → 0.0.1.pre129

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/History.rdoc +1 -1
  2. data/IDEAS.rdoc +62 -0
  3. data/Manifest.txt +38 -7
  4. data/README.rdoc +124 -5
  5. data/Rakefile +22 -6
  6. data/bin/leash +102 -157
  7. data/contrib/hoetemplate/.autotest.erb +23 -0
  8. data/contrib/hoetemplate/History.rdoc.erb +4 -0
  9. data/contrib/hoetemplate/Manifest.txt.erb +8 -0
  10. data/contrib/hoetemplate/README.rdoc.erb +17 -0
  11. data/contrib/hoetemplate/Rakefile.erb +24 -0
  12. data/contrib/hoetemplate/data/file_name/apps/file_name_app +36 -0
  13. data/contrib/hoetemplate/data/file_name/templates/layout.tmpl.erb +13 -0
  14. data/contrib/hoetemplate/data/file_name/templates/top.tmpl.erb +8 -0
  15. data/contrib/hoetemplate/lib/file_name.rb.erb +18 -0
  16. data/contrib/hoetemplate/spec/file_name_spec.rb.erb +21 -0
  17. data/data/strelka/apps/hello-world +30 -0
  18. data/lib/strelka/app/defaultrouter.rb +49 -30
  19. data/lib/strelka/app/errors.rb +121 -0
  20. data/lib/strelka/app/exclusiverouter.rb +40 -0
  21. data/lib/strelka/app/filters.rb +18 -7
  22. data/lib/strelka/app/negotiation.rb +122 -0
  23. data/lib/strelka/app/parameters.rb +171 -14
  24. data/lib/strelka/app/paramvalidator.rb +751 -0
  25. data/lib/strelka/app/plugins.rb +66 -46
  26. data/lib/strelka/app/restresources.rb +499 -0
  27. data/lib/strelka/app/router.rb +73 -0
  28. data/lib/strelka/app/routing.rb +140 -18
  29. data/lib/strelka/app/templating.rb +12 -3
  30. data/lib/strelka/app.rb +174 -24
  31. data/lib/strelka/constants.rb +0 -20
  32. data/lib/strelka/exceptions.rb +29 -0
  33. data/lib/strelka/httprequest/acceptparams.rb +377 -0
  34. data/lib/strelka/httprequest/negotiation.rb +257 -0
  35. data/lib/strelka/httprequest.rb +155 -7
  36. data/lib/strelka/httpresponse/negotiation.rb +579 -0
  37. data/lib/strelka/httpresponse.rb +140 -0
  38. data/lib/strelka/logging.rb +4 -1
  39. data/lib/strelka/mixins.rb +53 -0
  40. data/lib/strelka.rb +22 -1
  41. data/spec/data/error.tmpl +1 -0
  42. data/spec/lib/constants.rb +0 -1
  43. data/spec/lib/helpers.rb +21 -0
  44. data/spec/strelka/app/defaultrouter_spec.rb +41 -35
  45. data/spec/strelka/app/errors_spec.rb +212 -0
  46. data/spec/strelka/app/exclusiverouter_spec.rb +220 -0
  47. data/spec/strelka/app/filters_spec.rb +196 -0
  48. data/spec/strelka/app/negotiation_spec.rb +73 -0
  49. data/spec/strelka/app/parameters_spec.rb +149 -0
  50. data/spec/strelka/app/paramvalidator_spec.rb +1059 -0
  51. data/spec/strelka/app/plugins_spec.rb +26 -19
  52. data/spec/strelka/app/restresources_spec.rb +393 -0
  53. data/spec/strelka/app/router_spec.rb +63 -0
  54. data/spec/strelka/app/routing_spec.rb +183 -9
  55. data/spec/strelka/app/templating_spec.rb +1 -2
  56. data/spec/strelka/app_spec.rb +265 -32
  57. data/spec/strelka/exceptions_spec.rb +53 -0
  58. data/spec/strelka/httprequest/acceptparams_spec.rb +282 -0
  59. data/spec/strelka/httprequest/negotiation_spec.rb +246 -0
  60. data/spec/strelka/httprequest_spec.rb +204 -14
  61. data/spec/strelka/httpresponse/negotiation_spec.rb +464 -0
  62. data/spec/strelka/httpresponse_spec.rb +114 -0
  63. data/spec/strelka/mixins_spec.rb +99 -0
  64. data.tar.gz.sig +1 -0
  65. metadata +175 -79
  66. metadata.gz.sig +2 -0
  67. data/IDEAS.textile +0 -174
  68. data/data/strelka/apps/strelka-admin +0 -65
  69. data/data/strelka/apps/strelka-setup +0 -26
  70. data/data/strelka/bootstrap-config.rb +0 -34
  71. data/data/strelka/templates/admin/console.tmpl +0 -21
  72. data/data/strelka/templates/layout.tmpl +0 -30
  73. data/lib/strelka/process.rb +0 -19
data/IDEAS.textile DELETED
@@ -1,174 +0,0 @@
1
- h1. Strelka Ideas
2
-
3
- h2. Leash
4
-
5
- The main command-line interface to Strelka. It is used to browse and edit Mongrel2 config
6
- databases, set up a Mongrel2 cluster, join an existing cluster, etc.
7
-
8
- h3. Browsing/Editing a Mongrel2 Config
9
-
10
- Running 'leash' with no sub-commands starts it up in shell
11
- mode:
12
-
13
- $ leash config.sqlite
14
- Opening shell for config DB: config.sqlite
15
-
16
- Create a new server:
17
-
18
- config.sqlite> mkserver test
19
- Creating a new server (2379AA53-9688-4831-9C8B-9E70FE8A7EB7)
20
-
21
- Show the list of Server configurations:
22
-
23
- config.sqlite> ls
24
-
25
- -- Servers:
26
- main {B5764D79-5BD5-4F43-8FCA-CBB7FD85C4EE}
27
- test {2379AA53-9688-4831-9C8B-9E70FE8A7EB7}
28
- admin {90A2890D-F386-4841-B664-5DD7FFE97C53}
29
-
30
- Now 'cd' into one of them and show its config, and any Hosts
31
- that live under it:
32
-
33
- config.sqlite> cd main
34
- config.sqlite/main> ls
35
-
36
- -- Server [main] {B5764D79-5BD5-4F43-8FCA-CBB7FD85C4EE}
37
- Name: 'Arrow Bootstrap'
38
- Chroot: '/var/www'
39
- Access log: '/logs/access.log'
40
- Error log: '/logs/error.log'
41
- Default Host: 'localhost'
42
- PID File: '/run/mongrel2.pid'
43
- Port: 3667
44
-
45
- -- Hosts:
46
- localhost
47
- deveiate /(.*).deveiate.org/
48
-
49
- Change into one of the hosts and show it:
50
-
51
- config.sqlite/main> cd localhost
52
- config.sqlite/main/localhost> ls
53
-
54
- -- Host [localhost]
55
-
56
- ID: 1
57
- Matching Rule: /(.*).deveiate.org/
58
- Maintenance Mode: no
59
-
60
- -- Routes
61
- dir / -> /public
62
- dir .png -> /images (reverse)
63
- dir .css -> /css (reverse)
64
- dir .js -> /js (reverse)
65
- proxy /proxy -> google.com:80
66
- handler /admin -> D613E7EE-E2EB-4699-A200-5C8ECAB45D5E
67
- tcp://127.0.0.1:9998 - tcp://127.0.0.1:9997
68
- handler @directory -> B7EFA46D-FEE4-432B-B80F-E8A9A2CC6FDB
69
- tcp://127.0.0.1:9996 - tcp://127.0.0.1:9995
70
- handler /directory -> B7EFA46D-FEE4-432B-B80F-E8A9A2CC6FDB
71
- tcp://127.0.0.1:9996 - tcp://127.0.0.1:9995
72
-
73
- ...etc...
74
-
75
-
76
- h3. Setting Up A Mongrel2 Cluster
77
-
78
- Leash also comes with subcommands for interacting with Mongrel2. You can start
79
- a new cluster using the 'setup' subcommand:
80
-
81
- server1$ leash setup
82
- Creating bootstrap config...
83
- Starting mongrel2...
84
- Starting up control app...
85
- Okay, point a browser at http://localhost:37772/
86
-
87
- At this point, you can either use further leash commands, or use the web
88
- interface:
89
-
90
- server1$ open http://localhost:37772/
91
-
92
-
93
-
94
- h3. Join a Mongrel2 Cluster
95
-
96
- Once you have the first node set up, you need only point 'leash' to the admin
97
- server running on the first host to set up and automatically configure
98
- additional Mongrel2 front-ends:
99
-
100
- server2$ leash join server1
101
-
102
- This uses a 0MQ service running from the admin server that publishes the
103
- config using Mongrel2's "config from anything" protocol, so when Mongrel2
104
- itself supports the 'zmq.so' plugin, you won't even need a local SQLite
105
- database.
106
-
107
-
108
- h2. Strelka Applications
109
-
110
- Strelka applications may be written in one of three styles: App, Process, or Service. Each of these can be mapped to one or more Mongrel2 'handler' routes, and may have one or more Filters applied to it to provide pre- and post-processing for requests and responses.
111
-
112
- An App is a stateless handler that contains routes that are matched against a requests's HTTP verb and URL, and an appropriate routine invoked.
113
-
114
- A Process is a stateful handler intended to make stateful processes with a lot of user interaction easy to write.
115
-
116
- A Service is an easy way of creating a REST-style service for one or more resources.
117
-
118
-
119
- h3. Routes
120
-
121
- Routed methods are given a Strelka::Request object, and are expected to return
122
- either a Strelka::Response or something that can be made into one.
123
-
124
- class HelloWorld < Strelka::App
125
- get do |req|
126
- return req.response << 'Hello, World!'
127
- end
128
- end # class HelloWorld
129
-
130
- h3. Parameters
131
-
132
- Routes can accept parameters in two ways: via the URI path, and via the query
133
- string.
134
-
135
- _We may add other ways later, e.g., via structured entity bodies
136
- like JSON, XML, YAML, etc_.
137
-
138
- The application can declare parameters globally, and then override them on a
139
- per-route basis:
140
-
141
- class UserManager < Strelka::App
142
-
143
- param :username, /\w+/, :required, :untaint
144
- param :id, /\d+/
145
-
146
- # :username gets validated and merged into query args; URI parameters
147
- # clobber query params
148
- get '/info/:username', :params => { :id => /[XRT]\d{4}-\d{8}/ } do |req|
149
- req.params_okay?
150
- req[:username]
151
- req.values_at( :id, :username )
152
- req.params.username
153
- req.matchdata[ :username ] # => MatchData object
154
-
155
- req.validation_errors
156
- end
157
-
158
- end # class UserManager
159
-
160
-
161
-
162
- h3. Content-negotiation
163
-
164
- Application responses are set to be of @Content-type@ 'application/octet-stream'
165
- and no @Content-encoding@ by default. You can change this default via
166
- declaratives:
167
-
168
- class BrowserApp < Strelka::App
169
- content_type 'text/html'
170
- content_encoding 'UTF-8'
171
-
172
- ...
173
- end
174
-
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pathname'
4
- require 'inversion'
5
- require 'strelka'
6
-
7
- # The Strelka admin web console.
8
- class Strelka::AdminConsole < Strelka::App
9
- plugins :templating, :routing
10
-
11
- default_content_type 'text/html'
12
-
13
- layout 'layout.tmpl'
14
- templates \
15
- :console => 'admin/console.tmpl'
16
-
17
-
18
- ### Initialize some application data.
19
- def initialize( * )
20
- super
21
-
22
- Mongrel2.logger = Strelka.logger
23
- Inversion.logger = Strelka.logger
24
- Configurability.logger = Strelka.logger
25
-
26
- @control = Mongrel2::Control.new
27
- end
28
-
29
-
30
- # GET / -- console view
31
- get do |req|
32
- tmpl = self.template( :console )
33
- tmpl.control = @control
34
- tmpl.servers = Mongrel2::Config.servers
35
-
36
- tmpl.strelka_version = Strelka.version_string( true )
37
- tmpl.mongrel2_version = Mongrel2.version_string( true )
38
- tmpl.inversion_version = Inversion.version_string( true )
39
-
40
- return tmpl
41
- end
42
-
43
- end # class Strelka::AdminConsole
44
-
45
- if __FILE__ == $0
46
- datadir = Pathname( __FILE__ ).dirname.parent
47
- templatedir = datadir + 'templates'
48
-
49
- # Log to the screen if STDERR is opened to one
50
- if $stderr.tty?
51
- Strelka.logger = Logger.new( $stderr )
52
- else
53
- Strelka.logger = Logger.new( 'admin-console.log' )
54
- end
55
-
56
- Strelka.logger.level = $VERBOSE ? Logger::DEBUG : Logger::INFO
57
-
58
- Inversion::Template.configure( :template_paths => [templatedir] )
59
- Mongrel2::Config.configure( :configdb => Strelka::Constants::DEFAULT_CONFIG_URI )
60
-
61
- Strelka::AdminConsole.run( 'admin-console' )
62
- end
63
-
64
-
65
-
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'inversion'
4
- require 'strelka'
5
-
6
- # The Strelka setup web application.
7
- class Strelka::SetupProcess < Strelka::Process
8
-
9
- layout 'setup/layout.tmpl'
10
-
11
- views :step1 => 'setup/step1',
12
- :step2 => 'setup/step2'
13
-
14
-
15
- ### Progress through the setup process.
16
- def main( req )
17
- params = show( :step1 )
18
- params = show( :step2, params )
19
-
20
- end
21
-
22
- end # class Strelka::AdminConsole
23
-
24
-
25
- Strelka::SetupProcess.run( 'strelka-setup' )
26
-
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'mongrel2/config'
4
- include Mongrel2::Config::DSL
5
-
6
- require 'strelka/constants'
7
- include Strelka::Constants
8
-
9
- # This is the config that's loaded by 'leash setup' to get the admin server
10
- # up and running.
11
-
12
- server 'admin' do
13
- name 'adminserver'
14
- port DEFAULT_ADMIN_PORT
15
- access_log '/logs/admin-access.log'
16
- error_log '/logs/admin-error.log'
17
- pid_file '/run/admin.pid'
18
-
19
- default_host 'localhost'
20
-
21
- host 'localhost' do
22
- route '/', handler( 'tcp://127.0.0.1:19999', 'admin-console' )
23
-
24
- route '/css', directory( 'data/strelka/static/css/', 'base.css', 'text/css' )
25
- route '/images', directory( 'data/strelka/static/images/' )
26
- route '/fonts', directory( 'data/strelka/static/fonts/' )
27
- route '/js', directory( 'data/strelka/static/js/', 'index.js', 'text/javascript' )
28
- end
29
- end
30
-
31
- setting "control_port", 'ipc://run/admin-control'
32
-
33
- mkdir_p 'logs'
34
- mkdir_p 'run'
@@ -1,21 +0,0 @@
1
- <?publish title ?>Admin Console<?end publish ?>
2
-
3
- <p>The admin console. Is you is, or is you isn't?</p>
4
-
5
- <ul>
6
- <li>Strelka: <?attr strelka_version ?></li>
7
- <li>Mongrel2: <?attr mongrel2_version ?></li>
8
- <li>Inversion: <?attr inversion_version ?></li>
9
- </ul>
10
-
11
-
12
- <section id="mongrel2-status">
13
- <header>
14
- <h1>Mongrel Status</h1>
15
- </header>
16
-
17
- <table>
18
-
19
- </table>
20
- </section>
21
-
@@ -1,30 +0,0 @@
1
- <!doctype html>
2
- <head>
3
- <meta charset="utf-8">
4
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
5
-
6
- <title>Strelka: <?subscribe title ?></title>
7
- <meta name="author" content="Michael Granger">
8
-
9
- <meta name="viewport" content="width=device-width,initial-scale=1">
10
-
11
- <link rel="stylesheet" href="/css/master.css" type="text/css" media="screen"
12
- title="no title" charset="utf-8" />
13
- </head>
14
-
15
- <body>
16
-
17
- <header>
18
- <h1><?subscribe title ?></h1>
19
- </header>
20
-
21
- <section id="dump">
22
- <?attr body ?>
23
- </section>
24
-
25
- <footer>
26
- <p><tt>$Id$</tt></p>
27
- </footer>
28
-
29
- </body>
30
- </html>
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'mongrel2/handler'
4
- require 'strelka' unless defined?( Strelka )
5
-
6
-
7
- # The process-style handler base class.
8
- class Strelka::Process < Mongrel2::Handler
9
- include Strelka::Loggable,
10
- Strelka::Constants
11
-
12
- ### Create a new Process.
13
- def initialize( * )
14
- @
15
- end
16
-
17
-
18
- end # class Strelka::Process
19
-