reck 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e42763c73766c0f37b6d11774d0ae7d4c090e933142a293ab4fa8020fbc115c3
4
+ data.tar.gz: 0b34320493ef0739d2bbe5c6c21ae2bd28b02c823de789172f302f5bd930f884
5
+ SHA512:
6
+ metadata.gz: 605e3033cafec280edff30012a1214ed09df89c012488f7a762ce63014410a668a7f20742899898681b538ae84a84d52207965fcdc12996720d187fe1078f5d1
7
+ data.tar.gz: 70bcdc64891926d594082827225d43bf29c3490cb095478b5b1656784a73d4f0da64382073ac3ad43c13800fcd165eff707b6d71c0d253de80204ba7befeedd2
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Honeybadger Industries LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # Reck
2
+
3
+ An exception-based web framework for Ruby.
4
+
5
+ # Why another framework?
6
+
7
+ If you've ever programmed in Ruby on Rails, you know that it prefers convention
8
+ over configuration. We believe this approach works well as a design paradigm but
9
+ falls down over time (just ask anyone who has maintained a Rails application
10
+ since version 1). In order to remain competitive with newer high-level (and
11
+ often concurrent) programming languages like Node and Elixir, Ruby needs a
12
+ strong component-based framework which let's you use the *right* tool for the
13
+ job.
14
+
15
+ Reck is very light-weight compared to other web frameworks such as Rails
16
+ or even Sinatra. We handle the routing and controller layer using a very simple
17
+ exception-based DSL and then get out of the way so that any existing model or
18
+ view components may be used.
19
+
20
+ ## Installation
21
+
22
+ ```sh
23
+ $ gem install reck
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ To respond to the defined route with rendered content, simply raise an
29
+ exception. The message of the exception will be evaluated as ERB before being
30
+ added to the response. If the exception is raised without a message, a
31
+ no-content response will be sent. This exception-based DSL is dead-simple and
32
+ great for controlling the flow of your application.
33
+
34
+ Routing code to a controller is as simple as:
35
+
36
+ ```ruby
37
+ Reck.route '/' do |request|
38
+ raise Reck::Ok, 'Hello World'
39
+ end
40
+ ```
41
+
42
+ Want to add authentication? No problem. (Actually, with a single-page app, this *really is* all you need!)
43
+
44
+ ```ruby
45
+ Reck.route '/admin' do |request|
46
+ raise Reck::Forbidden unless request.params['username'] == 'admin'
47
+ raise Reck::Forbidden unless request.params['password'] == 'secret'
48
+ raise Reck::Ok, 'Super secret admin page'
49
+ end
50
+ ```
51
+
52
+ Since the message of each exception is actually a template, use ERB tags to
53
+ interpolate Ruby values in your views:
54
+
55
+ ```ruby
56
+ Reck.route '/version' do |request|
57
+ raise Reck::Ok, 'Reck version: <%= Reck::VERSION %>'
58
+ end
59
+ ```
60
+
61
+ Since Reck depends on Rack, you also have access to helper methods
62
+ derived from the keys in Rack's env hash:
63
+
64
+ ```ruby
65
+ Reck.route '/method' do |request|
66
+ raise Reck::Ok, 'Requested via: <%= request_method %>'
67
+ end
68
+ ```
69
+
70
+ To run the application server:
71
+
72
+ ```sh
73
+ $ ruby -r reck application.rb
74
+ ```
75
+
76
+ ## Supported Responses
77
+
78
+ Each response inherits from the exception `Reck::Response`.
79
+
80
+ | Exception Class | Status code |
81
+ | --------------------- | ----------- |
82
+ | Reck::Ok | 200 |
83
+ | Reck::Created | 201 |
84
+ | Reck::Forbidden | 403 |
85
+ | Reck::NotFound | 404 |
86
+
87
+ ## Handling exceptions
88
+
89
+ While responses should always be raised, you may wish to handle other types of
90
+ unexpected exceptions, or "exceptional exceptions", if you will. In these cases,
91
+ we recommend using Honeybadger. Honeybadger provides middleware (and a bunch of
92
+ other cool features) to catch exceptions in Ruby applications -- whether you're
93
+ using Reck, Rails, Sinatra, Rack, or rolling your own Ruby web-framework.
94
+
95
+ There are two ways you can get Honeybadger to monitor Reck:
96
+
97
+ 1. Reporting errors inside a controller
98
+
99
+ ```ruby
100
+ require 'reck'
101
+ require 'honeybadger'
102
+
103
+ Honeybadger.configure do |config|
104
+ config.api_key = 'your_api_key'
105
+ end
106
+
107
+ Reck.route '/oops' do |request|
108
+ begin
109
+ fail 'oops!'
110
+ rescue Reck::Response
111
+ raise # Raise the response to the router
112
+ rescue => e
113
+ # Exceptional Reck exception: report it with Honeybadger!
114
+ Honeybadger.notify(e)
115
+ end
116
+ end
117
+ ```
118
+
119
+ ```sh
120
+ ruby application.rb
121
+ ```
122
+
123
+ 2. Automatically catching all errors which aren't responses
124
+
125
+ ```ruby
126
+ require 'reck/application'
127
+ require 'honeybadger'
128
+
129
+ Honeybadger.configure do |config|
130
+ config.api_key = 'your_api_key'
131
+ config.exceptions.ignore << Reck::Response
132
+ end
133
+
134
+ Reck.route '/oops' do |request|
135
+ fail 'oops!'
136
+ end
137
+
138
+ use Honeybadger::Rack::ErrorNotifier
139
+
140
+ run Reck::Application
141
+ ```
142
+
143
+ ```sh
144
+ rackup application.ru
145
+ ```
146
+
147
+ Don't forget to replace `'your_api_key'` with the API key from your [project
148
+ settings page](https://www.honeybadger.io/) on Honeybadger.
149
+
150
+ ## TODO
151
+
152
+ - [ ] Handle all HTTP 1.1 status codes
153
+ - [ ] Access to response headers
154
+ - [ ] Custom response formats
155
+
156
+ ## Contributing
157
+
158
+ 1. Fork it.
159
+ 2. Create a topic branch `git checkout -b my_branch`
160
+ 3. Commit your changes `git commit -am "Boom"`
161
+ 3. Push to your branch `git push origin my_branch`
162
+ 4. Send a [pull request](https://github.com/honeybadger-io/reck/pulls)
163
+
164
+ ## License
165
+
166
+ Reck is Copyright 2015 © Honeybadger Industries LLC. It is free software, and
167
+ may be redistributed under the terms specified in the LICENSE file.
168
+
169
+ Brought to you by :zap: **Honeybadger.io**: our kick-ass exception tracking is no joke. :trollface:
170
+ [Start exterminating errors in your Ruby apps today](https://www.honeybadger.io/)!
@@ -0,0 +1,70 @@
1
+ require 'rack'
2
+ require 'forwardable'
3
+ require 'erb'
4
+
5
+ require 'reck/version'
6
+
7
+ module Reck
8
+ class Response < RuntimeError
9
+ NOT_BLANK = Regexp.new('\S').freeze
10
+
11
+ def head?
12
+ message == self.class.name || message !~ NOT_BLANK
13
+ end
14
+
15
+ def render
16
+ erb = ERB.new(message)
17
+ erb.result
18
+ end
19
+ end
20
+
21
+ class Ok < Response; end
22
+ class Created < Response; end
23
+ class Forbidden < Response; end
24
+ class NotFound < Response; end
25
+
26
+ STATUS = {
27
+ Ok => 200,
28
+ Created => 201,
29
+ Forbidden => 403,
30
+ NotFound => 404
31
+ }.freeze
32
+
33
+ class Application
34
+ def self.call(env)
35
+ req = Rack::Request.new(env)
36
+ if route = routes.find {|r| r.path.chomp('/') == req.path_info.chomp('/') }
37
+ route.call(req)
38
+ fail 'invalid response'
39
+ else
40
+ [404, {}, ['Not Found']]
41
+ end
42
+ rescue Reck::Response => e
43
+ [STATUS[e.class], {}, [e.head? ? nil : e.render].compact]
44
+ rescue => e
45
+ env['rack.exception'] = e
46
+ [500, {}, ['Internal Server Error']]
47
+ end
48
+
49
+ def self.routes
50
+ @@routes ||= []
51
+ end
52
+ end
53
+
54
+ class Route
55
+ extend Forwardable
56
+ attr_reader :path
57
+ def_delegator :@block, :call
58
+
59
+ def initialize(path, block)
60
+ @path = path
61
+ @block = block
62
+ end
63
+ end
64
+
65
+ def route(path, &block)
66
+ Application.routes.unshift(Route.new(path, block))
67
+ end
68
+
69
+ extend self
70
+ end
@@ -0,0 +1,3 @@
1
+ module Reck
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/reck.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'reck/application'
2
+
3
+ module Reck
4
+ at_exit do
5
+ Rack::Handler::WEBrick.run Reck::Application
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Honeybadger Industries LLC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - support@honeybadger.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - lib/reck.rb
37
+ - lib/reck/application.rb
38
+ - lib/reck/version.rb
39
+ homepage: https://github.com/honeybadger-io/reck
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.1.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.7.3
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: An exception-based web framework for Ruby.
63
+ test_files: []