wd_sinatra 1.0.6 → 2.0.0
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.
- checksums.yaml +7 -0
- data/.travis.yml +1 -4
- data/CHANGELOG.md +20 -0
- data/Gemfile +0 -2
- data/LICENSE +4 -2
- data/README.md +28 -19
- data/bin/wd_sinatra +7 -25
- data/lib/wd_sinatra/app_loader.rb +12 -20
- data/lib/wd_sinatra/sinatra_ext.rb +8 -7
- data/lib/wd_sinatra/test_helpers.rb +1 -1
- data/lib/wd_sinatra/version.rb +2 -4
- data/templates/Gemfile +16 -11
- data/templates/{Rakefile → Rakefile.tt} +4 -4
- data/templates/Thorfile +14 -8
- data/templates/api/hello_world.rb +17 -10
- data/templates/bin/console +1 -1
- data/templates/config.ru.tt +6 -0
- data/templates/config/sinatra_config.rb.tt +50 -0
- data/templates/lib/{app.rb → app.rb.tt} +4 -1
- data/templates/lib/hooks.rb +25 -15
- data/templates/test/{test_helpers.rb → test_helpers.rb.tt} +8 -6
- data/test/test_helper.rb +0 -4
- data/test/ws_list_ext_test.rb +6 -6
- data/wd-sinatra.gemspec +11 -7
- metadata +72 -104
- data/templates/config.ru +0 -5
- data/templates/config/middleware.rb +0 -16
- data/templates/config/sinatra_config.rb +0 -18
- data/templates/lib/body_parser.rb +0 -24
- data/templates/lib/tasks/doc.rake +0 -39
- data/templates/lib/tasks/doc_generator/bootstrap/.gitignore +0 -4
- data/templates/lib/tasks/doc_generator/bootstrap/LICENSE +0 -176
- data/templates/lib/tasks/doc_generator/bootstrap/Makefile +0 -47
- data/templates/lib/tasks/doc_generator/bootstrap/README.md +0 -105
- data/templates/lib/tasks/doc_generator/bootstrap/bootstrap.css +0 -2467
- data/templates/lib/tasks/doc_generator/bootstrap/bootstrap.min.css +0 -356
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/css/docs.css +0 -317
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/ico/bootstrap-apple-114x114.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/ico/bootstrap-apple-57x57.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/ico/bootstrap-apple-72x72.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/ico/favicon.ico +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/img/bird.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/img/browsers.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/img/example-diagram-01.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/img/example-diagram-02.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/img/example-diagram-03.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/img/grid-18px.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/img/twitter-logo-no-bird.png +0 -0
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/js/application.js +0 -52
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/js/google-code-prettify/prettify.css +0 -94
- data/templates/lib/tasks/doc_generator/bootstrap/docs/assets/js/google-code-prettify/prettify.js +0 -28
- data/templates/lib/tasks/doc_generator/bootstrap/docs/index.html +0 -2037
- data/templates/lib/tasks/doc_generator/bootstrap/docs/javascript.html +0 -798
- data/templates/lib/tasks/doc_generator/bootstrap/examples/container-app.html +0 -119
- data/templates/lib/tasks/doc_generator/bootstrap/examples/fluid.html +0 -122
- data/templates/lib/tasks/doc_generator/bootstrap/examples/hero.html +0 -79
- data/templates/lib/tasks/doc_generator/bootstrap/js/bootstrap-alerts.js +0 -124
- data/templates/lib/tasks/doc_generator/bootstrap/js/bootstrap-buttons.js +0 -64
- data/templates/lib/tasks/doc_generator/bootstrap/js/bootstrap-dropdown.js +0 -55
- data/templates/lib/tasks/doc_generator/bootstrap/js/bootstrap-modal.js +0 -260
- data/templates/lib/tasks/doc_generator/bootstrap/js/bootstrap-popover.js +0 -90
- data/templates/lib/tasks/doc_generator/bootstrap/js/bootstrap-scrollspy.js +0 -107
- data/templates/lib/tasks/doc_generator/bootstrap/js/bootstrap-tabs.js +0 -80
- data/templates/lib/tasks/doc_generator/bootstrap/js/bootstrap-twipsy.js +0 -321
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/index.html +0 -40
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-alerts.js +0 -41
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-buttons.js +0 -42
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-dropdown.js +0 -52
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-modal.js +0 -151
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-popover.js +0 -76
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-scrollspy.js +0 -31
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-tabs.js +0 -77
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/unit/bootstrap-twipsy.js +0 -81
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/vendor/qunit.css +0 -232
- data/templates/lib/tasks/doc_generator/bootstrap/js/tests/vendor/qunit.js +0 -1510
- data/templates/lib/tasks/doc_generator/bootstrap/lib/bootstrap.less +0 -26
- data/templates/lib/tasks/doc_generator/bootstrap/lib/forms.less +0 -479
- data/templates/lib/tasks/doc_generator/bootstrap/lib/mixins.less +0 -222
- data/templates/lib/tasks/doc_generator/bootstrap/lib/patterns.less +0 -1060
- data/templates/lib/tasks/doc_generator/bootstrap/lib/reset.less +0 -141
- data/templates/lib/tasks/doc_generator/bootstrap/lib/scaffolding.less +0 -139
- data/templates/lib/tasks/doc_generator/bootstrap/lib/tables.less +0 -224
- data/templates/lib/tasks/doc_generator/bootstrap/lib/type.less +0 -187
- data/templates/lib/tasks/doc_generator/bootstrap/lib/variables.less +0 -60
- data/templates/lib/tasks/doc_generator/template.erb +0 -156
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bcfdd3f7270b9b8af82313f82834e1a552ce38b0
|
4
|
+
data.tar.gz: 329ae8fdcadd521ca9b2e9897bc345f3845dcdf1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7de8b03a85a980d0c46f5745a41d40ee6bdaef49fada627559f8ebdfc047a81cc8d445c69d2177c9e34e30e8e13858f4cfe3ba20e37e0fe68ecb6fe538ad938f
|
7
|
+
data.tar.gz: 9b5d02e48b015b6c811927d80f3f81dc7bf8a361483490f3209232c904a3811853ea1d2e6865fbed5bb3599f1dc9ac04f4752c9c158d10bb0b11993b02e98363
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# Weasel Diesel Sinatra Changelog
|
2
2
|
|
3
|
+
## 2.0.0:
|
4
|
+
### Major Changes (Backwards Incompatible)
|
5
|
+
* Switch generated Sinatra app from classic to modular style.
|
6
|
+
* Set content_type depending on service.formats and http accept header.
|
7
|
+
* Drop support for ruby `1.8.7`.
|
8
|
+
|
9
|
+
### New Features
|
10
|
+
* Replace custom BodyParser with `rack-parser` middleware.
|
11
|
+
* Use `rerun` gem for auto code reloading in development/test.
|
12
|
+
* Wrap doc generation from WeaselDiesel::CLI. Documentation is
|
13
|
+
generated via thor now, instead of rake.
|
14
|
+
* Update doc generation to support optional namespaces.
|
15
|
+
* Simpler, more compact documentation template.
|
16
|
+
Removes `WD::Response::Element#to_html` and Bootstrap dependencies.
|
17
|
+
* Remove activesupport as a dependency, use inflecto for inflection support.
|
18
|
+
|
19
|
+
### Resolved issues
|
20
|
+
* Fix conflict with current Sinatra's `template`.
|
21
|
+
* Fix ul tag not rendering in doc generator.
|
22
|
+
|
3
23
|
## 1.0.6
|
4
24
|
* Updated various dependencies to get the latest versions of WD, Rack,
|
5
25
|
Sinatra to get the bug & security fixes.
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
MIT: http://mattaimonetti.mit-license.org
|
2
|
+
|
3
|
+
Copyright (c) 2013 Matt Aimonetti
|
2
4
|
|
3
5
|
MIT License
|
4
6
|
|
@@ -19,4 +21,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
21
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
22
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
23
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://next.travis-ci.org/mattetti/wd-sinatra)
|
4
4
|
|
5
|
-
Weasel
|
5
|
+
Weasel Diesel Sinatra app gem, allowing you to generate/update sinatra apps using the [Weasel-Diesel](https://github.com/mattetti/Weasel-Diesel) DSL.
|
6
6
|
|
7
7
|
|
8
8
|
## Installation
|
@@ -38,16 +38,15 @@ The app is now ready to use, to start it you can use rack:
|
|
38
38
|
This will start the server on port 9292 and the default GET `/hello_world` service will be available at: `http://localhost:9292/hello_world'.
|
39
39
|
|
40
40
|
Note that the code won't be reloading automatically in the server when
|
41
|
-
you make a modification to the source code. For that,
|
42
|
-
|
43
|
-
|
44
|
-
differently and it seems more sensitive to let them pick the way they
|
45
|
-
like the most.
|
41
|
+
you make a modification to the source code. For that, we include
|
42
|
+
[rerun](https://github.com/alexch/rerun), which is only enabled in the
|
43
|
+
development and test environments. Use it like this:
|
46
44
|
|
45
|
+
$ bundle exec rerun -- rackup
|
47
46
|
|
48
47
|
### Generating a new service
|
49
48
|
|
50
|
-
You need to have thor installed for that, you might want to add it
|
49
|
+
You need to have thor and active support installed for that, you might want to add it to
|
51
50
|
your gemfile.
|
52
51
|
|
53
52
|
$ thor :service get /foo/bar foo_bar.rb
|
@@ -73,15 +72,19 @@ $abspath/../../bin/console
|
|
73
72
|
|
74
73
|
### ORM
|
75
74
|
|
76
|
-
By default the generated app doesn't come with any ORMs, but if you want to use ActiveRecord, you can use
|
77
|
-
|
75
|
+
By default the generated app doesn't come with any ORMs, but if you want to use ActiveRecord, you can use these gems:
|
76
|
+
|
77
|
+
* [wd_sinatra_active_record](https://github.com/mattetti/wd_sinatra_active_record)
|
78
|
+
* [wd_sinatra_sequel](https://github.com/kamui/wd_sinatra_sequel)
|
78
79
|
|
79
80
|
|
80
81
|
### Documentation generation
|
81
82
|
|
82
|
-
|
83
|
+
```bash
|
84
|
+
$ thor generate_doc <DESTINATION PATH>
|
85
|
+
```
|
83
86
|
|
84
|
-
To generate documentation for the APIs you created in the api folder.
|
87
|
+
To generate documentation for the APIs you created in the api folder. The destination is optional, 'doc' is the default.
|
85
88
|
|
86
89
|
### Testing
|
87
90
|
|
@@ -156,7 +159,7 @@ TODO see Weasel Diesel for now and the generated service example.
|
|
156
159
|
|
157
160
|
### app.rb
|
158
161
|
|
159
|
-
The `
|
162
|
+
The `lib/app.rb` file is being required after the environment is set
|
160
163
|
but before the models are loaded. This is the perfect place to load
|
161
164
|
custom libraries and set your datastore.
|
162
165
|
|
@@ -201,22 +204,28 @@ These hooks have access to the entire request context, including the
|
|
201
204
|
`service` being called. You can use the service `extra` option to set
|
202
205
|
some custom settings that can then be used in this pre dispatch hook.
|
203
206
|
|
204
|
-
In the default generated application,
|
205
|
-
|
206
|
-
|
207
|
+
In the default generated application, [rack-parser](https://github.com/achiu/rack-parser)
|
208
|
+
is used to parse the body of json requests. By default, this uses the `JSON`
|
209
|
+
to parse the body. This can be [overwritten](https://github.com/achiu/rack-parser#content-type-parsing)
|
210
|
+
if you choose.
|
211
|
+
|
212
|
+
Say you want to use [Oj](https://github.com/ohler55/oj) instead. To do
|
213
|
+
that, edit the `config/sinatra_config.rb` file and change the following:
|
207
214
|
|
208
215
|
```ruby
|
209
|
-
|
216
|
+
use Rack::Parser
|
210
217
|
```
|
211
218
|
|
212
219
|
to:
|
213
220
|
|
214
221
|
```ruby
|
215
|
-
|
222
|
+
use Rack::Parser, :parsers => {
|
223
|
+
'application/json' => proc { |body| Oj.dump body }
|
224
|
+
}
|
216
225
|
```
|
217
226
|
|
218
|
-
Of course, you'll need to require `
|
219
|
-
Gemfile if
|
227
|
+
Of course, you'll need to `require 'oj'` first and add it to your
|
228
|
+
Gemfile if use Bundler.
|
220
229
|
|
221
230
|
|
222
231
|
## Update
|
data/bin/wd_sinatra
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "rubygems"
|
3
3
|
require "thor/group"
|
4
|
+
require "inflecto"
|
4
5
|
|
5
6
|
class WdSinatra < Thor::Group
|
6
7
|
include Thor::Actions
|
@@ -14,37 +15,18 @@ class WdSinatra < Thor::Group
|
|
14
15
|
File.expand_path(File.join('..', 'templates'), File.dirname(__FILE__))
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
directory "
|
18
|
+
def create_app
|
19
|
+
directory ".", "#{name}"
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
directory "config", "#{name}/config"
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_bin_directory
|
26
|
-
directory "bin", "#{name}/bin"
|
22
|
+
def chmod_bin_console
|
27
23
|
chmod "#{name}/bin/console", 0755
|
28
24
|
end
|
29
25
|
|
30
|
-
|
31
|
-
|
26
|
+
protected
|
27
|
+
def name_const
|
28
|
+
@name_const ||= Inflecto.camelize(name.gsub(/\W/, '_').squeeze('_'))
|
32
29
|
end
|
33
|
-
|
34
|
-
def create_api_directory
|
35
|
-
directory "api", "#{name}/api"
|
36
|
-
end
|
37
|
-
|
38
|
-
def create_test_directory
|
39
|
-
directory "test", "#{name}/test"
|
40
|
-
end
|
41
|
-
|
42
|
-
def create_files
|
43
|
-
%W{Rakefile Gemfile config.ru Guardfile Thorfile}.each do |filename|
|
44
|
-
copy_file filename, "#{name}/#{filename}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
30
|
end
|
49
31
|
|
50
32
|
WdSinatra.start
|
@@ -1,10 +1,7 @@
|
|
1
|
-
if RUBY_VERSION =~ /1.8/
|
2
|
-
require 'rubygems'
|
3
|
-
require 'backports'
|
4
|
-
end
|
5
1
|
require 'bundler'
|
6
2
|
Bundler.setup
|
7
3
|
require 'logger'
|
4
|
+
require 'sinatra/base'
|
8
5
|
require 'weasel_diesel'
|
9
6
|
require 'wd_sinatra/ws_list_ext'
|
10
7
|
|
@@ -12,20 +9,18 @@ module WDSinatra
|
|
12
9
|
module AppLoader
|
13
10
|
module_function
|
14
11
|
|
15
|
-
# Boot
|
16
|
-
def server(
|
17
|
-
|
18
|
-
unless @
|
19
|
-
console(root_path)
|
20
|
-
load_middleware
|
21
|
-
set_sinatra_routes
|
12
|
+
# Boot server
|
13
|
+
def server(sinatra_app=nil)
|
14
|
+
raise StandardError, "WDSinatra::AppLoader#setup must be run first." unless root_path
|
15
|
+
unless @server_loaded
|
22
16
|
set_sinatra_settings
|
17
|
+
set_sinatra_routes(sinatra_app)
|
23
18
|
load_hooks
|
19
|
+
@server_loaded = true
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
27
|
-
|
28
|
-
def console(root_path)
|
23
|
+
def setup(root_path)
|
29
24
|
@root = root_path
|
30
25
|
unless @booted
|
31
26
|
set_env
|
@@ -84,7 +79,7 @@ module WDSinatra
|
|
84
79
|
def load_lib_dependencies
|
85
80
|
# WeaselDiesel is the web service DSL gem used to define services.
|
86
81
|
require 'weasel_diesel'
|
87
|
-
require 'sinatra'
|
82
|
+
require 'sinatra/base'
|
88
83
|
require 'wd_sinatra/sinatra_ext'
|
89
84
|
end
|
90
85
|
|
@@ -106,12 +101,9 @@ module WDSinatra
|
|
106
101
|
end
|
107
102
|
end
|
108
103
|
|
109
|
-
def set_sinatra_routes
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
def load_middleware
|
114
|
-
require File.join(root_path, 'config', 'middleware')
|
104
|
+
def set_sinatra_routes(sinatra_app)
|
105
|
+
sinatra_app ||= Sinatra::Base
|
106
|
+
WSList.sorted_for_sinatra_load.each{|api| api.load_sinatra_route(sinatra_app) }
|
115
107
|
end
|
116
108
|
|
117
109
|
def set_sinatra_settings
|
@@ -57,11 +57,11 @@ class WeaselDiesel
|
|
57
57
|
@request = app.request
|
58
58
|
@response = app.response
|
59
59
|
@service = service
|
60
|
-
|
60
|
+
|
61
61
|
begin
|
62
62
|
# raises an exception if the params are not valid
|
63
|
-
# otherwise update the app params with potentially new params (using default values)
|
64
|
-
# note that if a type is mentioned for a params, the object will be cast to this object type
|
63
|
+
# otherwise update the app params with potentially new params (using default values)
|
64
|
+
# note that if a type is mentioned for a params, the object will be cast to this object type
|
65
65
|
#
|
66
66
|
# removing the fake sinatra params since v1.3 added this. (should be eventually removed)
|
67
67
|
if app.params['splat']
|
@@ -73,7 +73,7 @@ class WeaselDiesel
|
|
73
73
|
@params = params_preprocessor_hook(@params) if self.respond_to?(:params_preprocessor_hook)
|
74
74
|
@params = ParamsVerification.validate!(@params, service.defined_params)
|
75
75
|
@params = params_postprocessor_hook(@params) if self.respond_to?(:params_postprocessor_hook)
|
76
|
-
rescue
|
76
|
+
rescue ParamsVerification::ParamError => e
|
77
77
|
LOGGER.error e.message
|
78
78
|
LOGGER.error "passed params: #{app.params.inspect}"
|
79
79
|
if self.respond_to?(:params_exception_handler)
|
@@ -89,7 +89,7 @@ class WeaselDiesel
|
|
89
89
|
|
90
90
|
# Forwarding some methods to the underlying app object
|
91
91
|
def_delegators :app, :settings, :halt, :compile_template, :session
|
92
|
-
|
92
|
+
|
93
93
|
private ##################################################
|
94
94
|
|
95
95
|
end # of RequestHandler
|
@@ -109,7 +109,8 @@ class WeaselDiesel
|
|
109
109
|
@alpha_handler
|
110
110
|
end
|
111
111
|
|
112
|
-
def load_sinatra_route
|
112
|
+
def load_sinatra_route(sinatra_app=nil)
|
113
|
+
sinatra_app ||= Sinatra::Base
|
113
114
|
service = self
|
114
115
|
upcase_verb = service.verb.to_s.upcase
|
115
116
|
unless ENV['DONT_PRINT_ROUTES']
|
@@ -120,7 +121,7 @@ class WeaselDiesel
|
|
120
121
|
# Define the route directly to save some object allocations on the critical path
|
121
122
|
# Note that we are using a private API to define the route and that unlike sinatra usual DSL
|
122
123
|
# we do NOT define a HEAD route for every GET route.
|
123
|
-
|
124
|
+
sinatra_app.send(:route, upcase_verb, self.url) do
|
124
125
|
env['wd.service'] = service
|
125
126
|
service.handler.dispatch(self)
|
126
127
|
end
|
data/lib/wd_sinatra/version.rb
CHANGED
data/templates/Gemfile
CHANGED
@@ -1,21 +1,26 @@
|
|
1
|
-
source "
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
# web engine
|
4
|
-
gem "sinatra", "1.3.2"
|
5
|
-
# service DSL
|
6
|
-
gem "weasel_diesel"
|
7
3
|
gem "wd_sinatra"
|
8
|
-
|
4
|
+
gem "inflecto"
|
5
|
+
# gem "wd_newrelic_rpm", :require => "newrelic_rpm"
|
9
6
|
|
10
|
-
gem
|
11
|
-
gem
|
7
|
+
gem "backports", ">= 2.3.0", :platforms => "ruby_18"
|
8
|
+
gem "json", :platforms => "ruby_18"
|
12
9
|
|
13
10
|
group :development, :test do
|
14
|
-
gem "rack-test", "0.6.1"
|
11
|
+
gem "rack-test", ">= 0.6.1"
|
15
12
|
# gem "foreman"
|
16
13
|
# gem "puma"
|
17
|
-
gem "minitest"
|
18
|
-
# gem "guard-puma"
|
14
|
+
gem "minitest", "~> 4.7.4"
|
19
15
|
# gem "guard-minitest"
|
20
16
|
gem "rake"
|
17
|
+
|
18
|
+
gem "rerun"
|
19
|
+
# You can optionally comment out libraries not matching your OS platform
|
20
|
+
# Even if you don't, only the gem supported by your OS will be used by rerun
|
21
|
+
gem "rb-fsevent", ">= 0.9.3" # Mac OS X
|
22
|
+
gem "rb-inotify", ">= 0.9" # Linux
|
23
|
+
gem "rb-kqueue", ">= 0.2" # FreeBSD, NetBSD, OpenBSD, and Darwin
|
24
|
+
require "rbconfig"
|
25
|
+
gem "wdm", ">= 0.1.0" if RbConfig::CONFIG["target_os"] =~ /mswin|mingw/i # Windows
|
21
26
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rbconfig'
|
2
1
|
require 'rake/testtask'
|
3
2
|
require 'rubygems'
|
4
3
|
require 'bundler'
|
@@ -19,7 +18,7 @@ task :default => :test
|
|
19
18
|
task :setup_app do
|
20
19
|
ENV['DONT_CONNECT'] ||= 'true'
|
21
20
|
begin
|
22
|
-
WDSinatra::AppLoader.
|
21
|
+
WDSinatra::AppLoader.setup(root)
|
23
22
|
rescue Exception => e
|
24
23
|
if defined?(ActiveRecord) && e.is_a?(ActiveRecord::ConnectionNotEstablished)
|
25
24
|
ENV['DONT_CONNECT'] == 'true' ? print(e.message+"\n") : raise(e)
|
@@ -31,12 +30,13 @@ end
|
|
31
30
|
|
32
31
|
task :environment do
|
33
32
|
ENV['DONT_CONNECT'] = nil
|
34
|
-
WDSinatra::AppLoader.
|
33
|
+
WDSinatra::AppLoader.setup(root)
|
34
|
+
WDSinatra::AppLoader.server(<%= name_const %>)
|
35
35
|
end
|
36
36
|
|
37
37
|
desc "Print the available routes"
|
38
38
|
task :routes do
|
39
|
-
WDSinatra::AppLoader.
|
39
|
+
WDSinatra::AppLoader.setup(root)
|
40
40
|
print "Available routes: \n"
|
41
41
|
WSList.all.each do |service|
|
42
42
|
print "#{service.http_verb.upcase}\t#{service.url}\n"
|
data/templates/Thorfile
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
$:.unshift File.expand_path("../lib", __FILE__)
|
3
3
|
require 'bundler'
|
4
|
-
require '
|
4
|
+
require 'inflecto'
|
5
|
+
require 'weasel_diesel/cli'
|
5
6
|
|
6
7
|
class Default < Thor
|
7
8
|
include Thor::Actions
|
8
|
-
|
9
|
+
|
10
|
+
desc "generate_doc DESTINATION_PATH", "Generate HTML documentation"
|
11
|
+
def generate_doc(destination_path="doc")
|
12
|
+
WeaselDiesel::CLI.new.generate_doc('api', destination_path)
|
13
|
+
end
|
14
|
+
|
9
15
|
desc "service VERB URI FILENAME", "Generate scaffolding for a new service"
|
10
16
|
def service(verb, route, path)
|
11
17
|
route = route.gsub(/^\//, "") # strip leading forward slash
|
@@ -16,10 +22,10 @@ class Default < Thor
|
|
16
22
|
service.formats :json
|
17
23
|
service.http_verb :#{verb.downcase}
|
18
24
|
service.disable_auth # on by default
|
19
|
-
|
25
|
+
|
20
26
|
# INPUT
|
21
27
|
service.param.string :name, :default => 'World', :doc => "The name of the person to greet."
|
22
|
-
|
28
|
+
|
23
29
|
# OUTPUT
|
24
30
|
service.response do |response|
|
25
31
|
response.object do |obj|
|
@@ -27,13 +33,13 @@ class Default < Thor
|
|
27
33
|
obj.datetime :at, :doc => "The timestamp of when the message was dispatched"
|
28
34
|
end
|
29
35
|
end
|
30
|
-
|
36
|
+
|
31
37
|
# DOCUMENTATION
|
32
38
|
service.documentation do |doc|
|
33
39
|
doc.overall "This service provides a simple hello world implementation example."
|
34
40
|
doc.example "<code>curl -I 'http://localhost:9292/hello_world?name=Matt'</code>"
|
35
41
|
end
|
36
|
-
|
42
|
+
|
37
43
|
# ACTION/IMPLEMENTATION
|
38
44
|
service.implementation do
|
39
45
|
halt 501, "Not Implemented, which is a pity, I'm sure"
|
@@ -41,8 +47,8 @@ class Default < Thor
|
|
41
47
|
end
|
42
48
|
RUBY
|
43
49
|
end
|
44
|
-
|
45
|
-
class_name =
|
50
|
+
|
51
|
+
class_name = Inflecto.classify(path_without_suffix).gsub(/::/, '') # strip modules; just want a unique class name for spec
|
46
52
|
create_file(File.join("test", "integration", "#{path_without_suffix}_test.rb")) do
|
47
53
|
<<-RUBY.gsub(/^\s{6}/, '')
|
48
54
|
require 'test_helpers'
|