cuba-errors 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 622292972f1ba6407afea44e2c838230527a7890
4
+ data.tar.gz: 69fafeb1ed8ca4245447e40acdba980827b8da5a
5
+ SHA512:
6
+ metadata.gz: b92ddf7cafd190a6af00e800a0f9e3de38c0618742e60390213cc471f29d0234fb794b4ea8636c276f46f2453213341344653cccffe07d90b82cfe33df2ff0e0
7
+ data.tar.gz: ae3d2f30c462e5144f9311181cec5ef73d185873daa8a07164c4efea7278262fe44982f85f3c0eb8ae3067705bcd808268ad9529bda1d924a13007398307a2ea
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Patricio Mac Adden
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ 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.
@@ -0,0 +1,61 @@
1
+ # Cuba::NotFound
2
+
3
+ Not found helper for Cuba.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cuba-errors'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install cuba-errors
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ See an example:
28
+
29
+ ```ruby
30
+ require 'cuba'
31
+ require 'cuba/errors'
32
+ require 'cuba/render'
33
+
34
+ Cuba.plugin Cuba::Errors
35
+ Cuba.plugin Cuba::Render
36
+
37
+ # This setting specifies which view is going to be used for rendering a 404
38
+ # page. If not set, nothing will be rendered.
39
+ Cuba.settings[:errors][:not_found] = 'not_found'
40
+
41
+ Cuba.define do
42
+ on default do
43
+ # sets status = 404
44
+ # sets Content-Type = text/html; charset=utf-8
45
+ # renders views/not_found.erb
46
+ not_found!
47
+ end
48
+ end
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
58
+
59
+ ## License
60
+
61
+ See the [LICENSE](https://github.com/patriciomacadden/cuba-errors/blob/master/LICENSE).
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task default: :test
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'cuba-errors'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Patricio Mac Adden']
9
+ spec.email = ['patriciomacadden@gmail.com']
10
+ spec.summary = %q{Error helpers for Cuba.}
11
+ spec.description = %q{Error helpers for Cuba.}
12
+ spec.homepage = 'https://github.com/patriciomacadden/cuba-errors'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'oktobertest'
22
+ spec.add_development_dependency 'oktobertest-contrib'
23
+ spec.add_development_dependency 'rack-test'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+
26
+ spec.add_runtime_dependency 'cuba', '~> 3.0'
27
+ spec.add_runtime_dependency 'tilt'
28
+ end
@@ -0,0 +1,29 @@
1
+ class Cuba
2
+ module Errors
3
+ def self.setup(app)
4
+ app.settings[:errors] ||= {}
5
+ end
6
+
7
+ def forbidden!
8
+ error! 403, :forbidden
9
+ end
10
+
11
+ def not_found!
12
+ error! 404, :not_found
13
+ end
14
+
15
+ def internal_server_error!
16
+ error! 500, :internal_server_error
17
+ end
18
+
19
+ private
20
+
21
+ def error!(status, view)
22
+ res.status = status
23
+ if settings[:errors].include? view
24
+ res.headers['Content-Type'] = 'text/html; charset=utf-8'
25
+ render settings[:errors][view]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,58 @@
1
+ require 'helper'
2
+
3
+ scope Cuba::Errors do
4
+ setup do
5
+ @app = Cuba
6
+ end
7
+
8
+ scope '#forbidden!' do
9
+ test 'sets status and headers' do
10
+ get '/forbidden'
11
+ assert_status 403
12
+ assert_equal '', last_response.body
13
+ end
14
+
15
+ test 'renders a template when settings[:errors][:forbidden] is set' do
16
+ Cuba.settings[:render][:views] = 'test/views'
17
+ Cuba.settings[:errors][:forbidden] = 'forbidden'
18
+ get '/forbidden'
19
+ assert_status 403
20
+ assert_header 'Content-Type', 'text/html; charset=utf-8'
21
+ assert_equal 'Forbidden!', last_response.body
22
+ end
23
+ end
24
+
25
+ scope '#not_found!' do
26
+ test 'sets status and headers' do
27
+ get '/not_found'
28
+ assert_status 404
29
+ assert_equal '', last_response.body
30
+ end
31
+
32
+ test 'renders a template when settings[:errors][:not_found] is set' do
33
+ Cuba.settings[:render][:views] = 'test/views'
34
+ Cuba.settings[:errors][:not_found] = 'not_found'
35
+ get '/not_found'
36
+ assert_status 404
37
+ assert_header 'Content-Type', 'text/html; charset=utf-8'
38
+ assert_equal 'Not Found!', last_response.body
39
+ end
40
+ end
41
+
42
+ scope '#internal_server_error!' do
43
+ test 'sets status and headers' do
44
+ get '/internal_server_error'
45
+ assert_status 500
46
+ assert_equal '', last_response.body
47
+ end
48
+
49
+ test 'renders a template when settings[:errors][:internal_server_error] is set' do
50
+ Cuba.settings[:render][:views] = 'test/views'
51
+ Cuba.settings[:errors][:internal_server_error] = 'internal_server_error'
52
+ get '/internal_server_error'
53
+ assert_status 500
54
+ assert_header 'Content-Type', 'text/html; charset=utf-8'
55
+ assert_equal 'Internal Server Error!', last_response.body
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,26 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'cuba'
4
+ require 'cuba/render'
5
+ require 'oktobertest'
6
+ require 'oktobertest/contrib'
7
+ require 'rack/test'
8
+
9
+ require 'cuba/errors'
10
+
11
+ Cuba.plugin Cuba::Render
12
+ Cuba.plugin Cuba::Errors
13
+
14
+ Cuba.define do
15
+ on 'forbidden' do
16
+ forbidden!
17
+ end
18
+
19
+ on 'not_found' do
20
+ not_found!
21
+ end
22
+
23
+ on 'internal_server_error' do
24
+ internal_server_error!
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ Forbidden!
@@ -0,0 +1 @@
1
+ Internal Server Error!
@@ -0,0 +1 @@
1
+ <%= content %>
@@ -0,0 +1 @@
1
+ Not Found!
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuba-errors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patricio Mac Adden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oktobertest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oktobertest-contrib
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cuba
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: tilt
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Error helpers for Cuba.
112
+ email:
113
+ - patriciomacadden@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - cuba-errors.gemspec
124
+ - lib/cuba/errors.rb
125
+ - test/cuba/errors_test.rb
126
+ - test/helper.rb
127
+ - test/views/forbidden.erb
128
+ - test/views/internal_server_error.erb
129
+ - test/views/layout.erb
130
+ - test/views/not_found.erb
131
+ homepage: https://github.com/patriciomacadden/cuba-errors
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.4.5.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Error helpers for Cuba.
155
+ test_files:
156
+ - test/cuba/errors_test.rb
157
+ - test/helper.rb
158
+ - test/views/forbidden.erb
159
+ - test/views/internal_server_error.erb
160
+ - test/views/layout.erb
161
+ - test/views/not_found.erb