pakyow-fail 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 139b6ec6fe5a9c6174a407e4fdea1e46604dc578
4
+ data.tar.gz: 9dd79969c81805fe18f2c21406494fbc4b37f12e
5
+ SHA512:
6
+ metadata.gz: 49e9cee59c3d57bab5bea5d85aae8fa6e443d5d4adb825ee504ad5d12c3f1ba72c3135750d50fffe001252ba5efa47a70dbb1a2292b8c90371d55eb2681b00bd
7
+ data.tar.gz: 81ff29a8b2709c6f867d4b164b7cab6de4226599c290ead71155b7b6bbfc890c9c8a2cecd8d62f7d6f8903d848be1fd21181b99ef960c3ec2e97ff7b9c101cbc
data/CHANGES ADDED
@@ -0,0 +1,3 @@
1
+ = 0.1.0 / 2014-11-14
2
+
3
+ * Initial gem release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Bryan Powell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ require_relative 'pakyow-fail/config'
2
+ require_relative 'pakyow-fail/routes'
3
+ require_relative 'pakyow-fail/handler'
4
+
5
+ Pakyow::Config.presenter.view_stores[:fail] = File.join(__dir__, 'pakyow-fail', 'views')
@@ -0,0 +1,10 @@
1
+ Pakyow::Config.register :fail do |config|
2
+ # the handlers available to be enabled
3
+ config.opt :available_handlers, {}
4
+
5
+ # the handlers to invoke when something fails
6
+ config.opt :enabled_handlers, []
7
+
8
+ # config values required by handlers
9
+ config.opt :required_config, {}
10
+ end
@@ -0,0 +1,19 @@
1
+ module Pakyow
2
+ module Fail
3
+ class Handler
4
+ def self.register(name, klass, required_config)
5
+ Config.fail.available_handlers[name] = klass
6
+ Config.fail.required_config[name] = required_config
7
+ end
8
+
9
+ def self.enable(name)
10
+ return if Config.fail.enabled_handlers.include?(name)
11
+ Config.fail.enabled_handlers << name
12
+ end
13
+
14
+ def self.disable(name)
15
+ Config.fail.enabled_handlers.delete(name)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ module Pakyow
2
+ module Fail
3
+ LOG_MSG = 'pakyow just enhanced your calm'
4
+
5
+ module Routes
6
+ include Pakyow::Routes
7
+
8
+ fn :fail do
9
+ catch :halt do
10
+ Config.fail.enabled_handlers.each do |handler_name|
11
+ # validate that required config is set
12
+ begin
13
+ Config.fail.required_config[handler_name].map { |config|
14
+ Config.fail.value(config)
15
+ }
16
+ rescue ConfigError => e
17
+ logger.error e.message
18
+ next
19
+ end
20
+
21
+ # invoke the handler
22
+ Config.fail.available_handlers.fetch(handler_name).new(self)
23
+ end
24
+ end
25
+ end
26
+
27
+ handler 404, :not_found do
28
+ logger.info LOG_MSG
29
+ presenter.path = '404'
30
+ view.title = "#{config.app.name} &#8250; 404 Not Found"
31
+ end
32
+
33
+ handler 500, :server_error, after: [:fail] do
34
+ logger.info LOG_MSG
35
+ presenter.path = '500'
36
+ view.title = "#{config.app.name} &#8250; 500 Internal Server Error"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ <h1>
2
+ 404 &ndash; Page Not Found
3
+ </h1>
4
+
5
+ <p class="instruct">
6
+ Sorry, we couldn't find the page you were looking for.
7
+ </p>
8
+
9
+ <p>
10
+ &#8249; <a href="/">Back Home</a>
11
+ </p>
@@ -0,0 +1,11 @@
1
+ <h1>
2
+ 500 &ndash; Internal Server Error
3
+ </h1>
4
+
5
+ <p class="instruct">
6
+ Well this is embarrassing, but it looks like something went wrong.
7
+ </p>
8
+
9
+ <p>
10
+ &#8249; <a href="/">Back Home</a>
11
+ </p>
@@ -0,0 +1,45 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+
6
+ <style>
7
+ body {
8
+ font:13px Helvetica Neue, Helvetica, sans-serif;
9
+ line-height:1.35em;
10
+ color:#333;
11
+ }
12
+
13
+ h1 {
14
+ font-size:20px;
15
+ color:#333;
16
+ }
17
+
18
+ h2 {
19
+ font-weight:normal;
20
+ font-size:13px;
21
+ color:#FF0000;
22
+ }
23
+
24
+ .wrapper {
25
+ width:900px;
26
+ margin:60px auto 0;
27
+ }
28
+
29
+ .instruct {
30
+ font-size:15px;
31
+ margin:30px 0;
32
+ color:#777;
33
+ }
34
+
35
+ a {
36
+ color:#19558d;
37
+ }
38
+ </style>
39
+ </head>
40
+ <body>
41
+ <div class="wrapper">
42
+ <!-- @container -->
43
+ </div>
44
+ </body>
45
+ </html>
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pakyow-fail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Powell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pakyow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ description: An failure handling library for Pakyow apps.
28
+ email: bryan@metabahn.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - "./CHANGES"
34
+ - "./MIT-LICENSE"
35
+ - "./lib/pakyow-fail.rb"
36
+ - "./lib/pakyow-fail/config.rb"
37
+ - "./lib/pakyow-fail/handler.rb"
38
+ - "./lib/pakyow-fail/routes.rb"
39
+ - "./lib/pakyow-fail/views/404.html"
40
+ - "./lib/pakyow-fail/views/500.html"
41
+ - "./lib/pakyow-fail/views/_templates/pakyow.html"
42
+ homepage: http://pakyow.com
43
+ licenses: []
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - "./lib"
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.0.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.2.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Pakyow failure handling.
65
+ test_files: []
66
+ has_rdoc: