strelka 0.0.1pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gemtest +0 -0
  2. data/History.rdoc +4 -0
  3. data/IDEAS.textile +174 -0
  4. data/Manifest.txt +38 -0
  5. data/README.rdoc +66 -0
  6. data/Rakefile +64 -0
  7. data/bin/leash +403 -0
  8. data/data/strelka/apps/strelka-admin +65 -0
  9. data/data/strelka/apps/strelka-setup +26 -0
  10. data/data/strelka/bootstrap-config.rb +34 -0
  11. data/data/strelka/templates/admin/console.tmpl +21 -0
  12. data/data/strelka/templates/layout.tmpl +30 -0
  13. data/lib/strelka/app/defaultrouter.rb +85 -0
  14. data/lib/strelka/app/filters.rb +70 -0
  15. data/lib/strelka/app/parameters.rb +64 -0
  16. data/lib/strelka/app/plugins.rb +205 -0
  17. data/lib/strelka/app/routing.rb +140 -0
  18. data/lib/strelka/app/templating.rb +157 -0
  19. data/lib/strelka/app.rb +175 -0
  20. data/lib/strelka/behavior/plugin.rb +36 -0
  21. data/lib/strelka/constants.rb +53 -0
  22. data/lib/strelka/httprequest.rb +52 -0
  23. data/lib/strelka/logging.rb +241 -0
  24. data/lib/strelka/mixins.rb +143 -0
  25. data/lib/strelka/process.rb +19 -0
  26. data/lib/strelka.rb +40 -0
  27. data/spec/data/layout.tmpl +3 -0
  28. data/spec/data/main.tmpl +1 -0
  29. data/spec/lib/constants.rb +32 -0
  30. data/spec/lib/helpers.rb +134 -0
  31. data/spec/strelka/app/defaultrouter_spec.rb +215 -0
  32. data/spec/strelka/app/parameters_spec.rb +74 -0
  33. data/spec/strelka/app/plugins_spec.rb +167 -0
  34. data/spec/strelka/app/routing_spec.rb +139 -0
  35. data/spec/strelka/app/templating_spec.rb +169 -0
  36. data/spec/strelka/app_spec.rb +160 -0
  37. data/spec/strelka/httprequest_spec.rb +54 -0
  38. data/spec/strelka/logging_spec.rb +72 -0
  39. data/spec/strelka_spec.rb +27 -0
  40. metadata +226 -0
data/.gemtest ADDED
File without changes
data/History.rdoc ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 [2011-08-29] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ Initial release.
4
+
data/IDEAS.textile ADDED
@@ -0,0 +1,174 @@
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
+
data/Manifest.txt ADDED
@@ -0,0 +1,38 @@
1
+ History.rdoc
2
+ IDEAS.textile
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/leash
7
+ data/strelka/apps/strelka-admin
8
+ data/strelka/apps/strelka-setup
9
+ data/strelka/bootstrap-config.rb
10
+ data/strelka/templates/admin/console.tmpl
11
+ data/strelka/templates/layout.tmpl
12
+ lib/strelka.rb
13
+ lib/strelka/app.rb
14
+ lib/strelka/app/defaultrouter.rb
15
+ lib/strelka/app/filters.rb
16
+ lib/strelka/app/parameters.rb
17
+ lib/strelka/app/plugins.rb
18
+ lib/strelka/app/routing.rb
19
+ lib/strelka/app/templating.rb
20
+ lib/strelka/behavior/plugin.rb
21
+ lib/strelka/constants.rb
22
+ lib/strelka/httprequest.rb
23
+ lib/strelka/logging.rb
24
+ lib/strelka/mixins.rb
25
+ lib/strelka/process.rb
26
+ spec/data/layout.tmpl
27
+ spec/data/main.tmpl
28
+ spec/lib/constants.rb
29
+ spec/lib/helpers.rb
30
+ spec/strelka/app/defaultrouter_spec.rb
31
+ spec/strelka/app/parameters_spec.rb
32
+ spec/strelka/app/plugins_spec.rb
33
+ spec/strelka/app/routing_spec.rb
34
+ spec/strelka/app/templating_spec.rb
35
+ spec/strelka/app_spec.rb
36
+ spec/strelka/httprequest_spec.rb
37
+ spec/strelka/logging_spec.rb
38
+ spec/strelka_spec.rb
data/README.rdoc ADDED
@@ -0,0 +1,66 @@
1
+ = strelka
2
+
3
+ * http://deveiate.org/projects/Strelka
4
+
5
+ == Description
6
+
7
+ Strelka is a framework for creating and deploying Mongrel2 web applications
8
+ in Ruby. It's still pre-alpha.
9
+
10
+ Strelka is named after a Russian dog who was one of the first space travelers
11
+ to orbit the Earth and return alive.
12
+
13
+
14
+ == Installation
15
+
16
+ gem install strelka
17
+
18
+
19
+ == Usage
20
+
21
+
22
+
23
+ == Contributing
24
+
25
+ You can check out the current development source with Mercurial via its
26
+ {project page}[http://repo.deveiate.org/Strelka]. Or if you prefer Git, via
27
+ {its Github mirror}[https://github.com/ged/strelka].
28
+
29
+ After checking out the source, run:
30
+
31
+ $ rake newb
32
+
33
+ This task will install any missing dependencies, run the tests/specs,
34
+ and generate the API documentation.
35
+
36
+
37
+ == License
38
+
39
+ Copyright (c) 2011, Michael Granger
40
+ All rights reserved.
41
+
42
+ Redistribution and use in source and binary forms, with or without
43
+ modification, are permitted provided that the following conditions are met:
44
+
45
+ * Redistributions of source code must retain the above copyright notice,
46
+ this list of conditions and the following disclaimer.
47
+
48
+ * Redistributions in binary form must reproduce the above copyright notice,
49
+ this list of conditions and the following disclaimer in the documentation
50
+ and/or other materials provided with the distribution.
51
+
52
+ * Neither the name of the author/s, nor the names of the project's
53
+ contributors may be used to endorse or promote products derived from this
54
+ software without specific prior written permission.
55
+
56
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
57
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
59
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
60
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
62
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
63
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
64
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
65
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66
+
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env rake
2
+
3
+ begin
4
+ require 'hoe'
5
+ rescue LoadError
6
+ abort "This Rakefile requires 'hoe' (gem install hoe)"
7
+ end
8
+
9
+ Hoe.plugin :mercurial
10
+ Hoe.plugin :signing
11
+
12
+ Hoe.plugins.delete :rubyforge
13
+
14
+ hoespec = Hoe.spec 'strelka' do
15
+ self.readme_file = 'README.rdoc'
16
+ self.history_file = 'History.rdoc'
17
+ self.extra_rdoc_files << 'README.rdoc' << 'History.rdoc'
18
+
19
+ self.developer 'Michael Granger', 'ged@FaerieMUD.org'
20
+
21
+ self.dependency 'mongrel2', '~> 0.2.3'
22
+ self.dependency 'configurability', '~> 1.0'
23
+ self.dependency 'inversion', '~> 0.1'
24
+
25
+ self.dependency 'tilt', '~> 1.3', :developer
26
+ self.dependency 'rspec', '~> 2.6', :developer
27
+
28
+ self.spec_extras[:licenses] = ["BSD"]
29
+ self.require_ruby_version( '>=1.8.7' )
30
+
31
+ self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
32
+ end
33
+
34
+ ENV['VERSION'] ||= hoespec.spec.version.to_s
35
+
36
+ # Ensure the specs pass before checking in
37
+ task 'hg:precheckin' => :spec
38
+
39
+ ### Make the ChangeLog update if the repo has changed since it was last built
40
+ file '.hg/branch'
41
+ file 'ChangeLog' => '.hg/branch' do |task|
42
+ $stderr.puts "Updating the changelog..."
43
+ content = make_changelog()
44
+ File.open( task.name, 'w', 0644 ) do |fh|
45
+ fh.print( content )
46
+ end
47
+ end
48
+
49
+ # Rebuild the ChangeLog immediately before release
50
+ task :prerelease => 'ChangeLog'
51
+
52
+
53
+ desc "Build a coverage report"
54
+ task :coverage do
55
+ ENV["COVERAGE"] = 'yes'
56
+ Rake::Task[:spec].invoke
57
+ end
58
+
59
+ if Rake::Task.task_defined?( '.gemtest' )
60
+ Rake::Task['.gemtest'].clear
61
+ task '.gemtest' do
62
+ $stderr.puts "Not including a .gemtest until I'm confident the test suite is idempotent."
63
+ end
64
+ end