four_o_four 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
+ SHA1:
3
+ metadata.gz: c56888a29ff641441b1617489a286c45cdffae74
4
+ data.tar.gz: 3ab8f1407a71606a2eae46b5f28e69b127d1904f
5
+ SHA512:
6
+ metadata.gz: ae1d58a685163bc7391799586ce174046803cd6c6458805d4b5ff7dc5f6d9fa8c178635c0f2f58456aff76bb8e275a05aa89d4dfdd0a2e54d206ea9a5e426303
7
+ data.tar.gz: 2beb20375740455db4aba69b56c9d27c808379285a0a2c5f8f1d4a918cb3781b138dd5b21a7140f241d0952ae4af41118645551fc0b53d7382ff0c723d69e01d
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.0.0
5
+ before_install: gem install bundler -v 1.11.2
6
+ addons:
7
+ code_climate:
8
+ repo_token: a90331fa182eaff67819978a9aac52143ac6654f1520a2f0ea8fe37f8d19c63e
9
+ engines:
10
+ markdownlint:
11
+ enabled: true
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at epmwgs@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in four_o_four.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ # watch /lib/ files
3
+ watch(%r{^lib/(.+).rb$}) do |m|
4
+ "spec/#{m[1]}_spec.rb"
5
+ end
6
+
7
+ # watch /spec/ files
8
+ watch(%r{^spec/(.+).rb$}) do |m|
9
+ "spec/#{m[1]}.rb"
10
+ end
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Espartaco Palma
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # FourOFour
2
+
3
+ [![Build
4
+ Status](https://travis-ci.org/esparta/four_o_four.svg?branch=master)](https://travis-ci.org/esparta/four_o_four)
5
+ [![Code
6
+ Climate](https://codeclimate.com/github/esparta/four_o_four/badges/gpa.svg)](https://codeclimate.com/github/esparta/four_o_four)
7
+ [![Test
8
+ Coverage](https://codeclimate.com/github/esparta/four_o_four/badges/coverage.svg)](https://codeclimate.com/github/esparta/four_o_four/coverage)
9
+
10
+ A super simple Rack middleware to capture 404 responses and change the response
11
+ for any other logic.
12
+
13
+ With FourOFour you will be able to handle your 404 responses and change
14
+ how your application behave dynamically and with the 'right' way: using a
15
+ class for a delegation, separating all the concerns. Routes and logic should
16
+ have their own space.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'four_o_four'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install four_o_four
33
+
34
+ ## Usage
35
+
36
+ After install you need to add this gem as a Rack application within your
37
+ application. On rails can be done like this:
38
+
39
+ ```ruby
40
+ module YourAwesomeApp
41
+ class Application < Rails::Application
42
+ # .... extra configuration
43
+ config.middleware.use 'FourOFour'
44
+ end
45
+ end
46
+ ```
47
+
48
+ This will activate every 404 and will take control of the 404 page displaying
49
+ a generic page saying
50
+
51
+ <h1>Default FourOuFour Application</h1>
52
+
53
+ Please configure your middleware to pass a delegation class
54
+
55
+ The interesting part comes with the configuration. You can pass a second
56
+ parameter to the configuration...
57
+
58
+ ```ruby
59
+ module YourAwesomeApp
60
+ class Application < Rails::Application
61
+ # .... extra configuration
62
+ config.middleware.use 'FourOFour', 'DelegatedClass'
63
+ end
64
+ end
65
+ ```
66
+
67
+ In this case, the `DelegatedClass` can be any other ruby class that will take
68
+ control of the 404 implementing your own logic. This still needs to be a Rack
69
+ application compatible. But nothing complicated.
70
+
71
+ ```ruby
72
+ class DelegatedClass
73
+ def call(env)
74
+ [200, {'Content-Type' => 'text/html'}, self ]
75
+ end
76
+
77
+ def each(&block)
78
+ block.call(random_msg)
79
+ end
80
+
81
+ def random_msg
82
+ ["Yo!, this is sad. I didn't know you got this. Sorry ",
83
+ "Dear Mr. or Ms. I'm really sorry about this 404",
84
+ 'Such is life'
85
+ ].sample
86
+ end
87
+ end
88
+ ```
89
+
90
+ ## Development
91
+
92
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
93
+
94
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
95
+
96
+ ## Contributing
97
+
98
+ Bug reports and pull requests are welcome on GitHub at https://github.com/esparta/four_o_four. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
99
+
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
104
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "four_o_four"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
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 = 'four_o_four'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Espartaco Palma']
9
+ spec.email = ['esparta@gmail.com']
10
+
11
+ spec.summary = <<-SUMMARY
12
+ FourOFour, a simple Rack middleware to handle 404 responses with delegation
13
+ SUMMARY
14
+ spec.description = <<-DESCRIPTION
15
+ With FourOFour you will be able to handle your 404 responses and change
16
+ how your application behave dynamically and with the 'right' way: using a
17
+ class for a delegation, separating all the concerns. Routes and logic should
18
+ have their own space.
19
+ DESCRIPTION
20
+ spec.homepage = 'https://github.com/esparta/four_o_four'
21
+ spec.license = 'MIT'
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'rack'
31
+ spec.add_dependency 'activesupport'
32
+ spec.add_development_dependency 'bundler', '~> 1.11'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.0'
35
+ spec.add_development_dependency 'rspec-nc'
36
+ spec.add_development_dependency 'guard'
37
+ spec.add_development_dependency 'guard-rspec'
38
+ spec.add_development_dependency 'pry'
39
+ spec.add_development_dependency 'pry-remote'
40
+ spec.add_development_dependency 'pry-nav'
41
+ spec.add_development_dependency 'codeclimate-test-reporter'
42
+ end
@@ -0,0 +1,34 @@
1
+ # Redirector...
2
+ require 'active_support/inflector'
3
+ # A small Rack middleware to handle 404 responses with a delegation
4
+ class FourOFour
5
+ VERSION = '0.0.2'
6
+ def initialize(app, delegation = nil)
7
+ @app = app
8
+ @delegation = delegation || "#{self.class}::DefaultApplication"
9
+ end
10
+
11
+ def call(env)
12
+ status, headers, response = @app.call(env)
13
+ if 404 == status
14
+ @delegation.constantize.new.call(env)
15
+ else
16
+ [status, headers, response]
17
+ end
18
+ end
19
+
20
+ # Default Application just in case we didn't set up on the middleware
21
+ class DefaultApplication
22
+ def call(_)
23
+ [200, { 'Content-Type' => 'text/html' }, self]
24
+ end
25
+
26
+ def each(&block)
27
+ block.call(
28
+ '''
29
+ <h1> Default FourOFour Application </h1>
30
+ Please configure your middleware to pass a delegation class
31
+ ''')
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: four_o_four
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Espartaco Palma
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-16 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
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-nc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-remote
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry-nav
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: codeclimate-test-reporter
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: |2
182
+ With FourOFour you will be able to handle your 404 responses and change
183
+ how your application behave dynamically and with the 'right' way: using a
184
+ class for a delegation, separating all the concerns. Routes and logic should
185
+ have their own space.
186
+ email:
187
+ - esparta@gmail.com
188
+ executables: []
189
+ extensions: []
190
+ extra_rdoc_files: []
191
+ files:
192
+ - .coveralls.yml
193
+ - .gitignore
194
+ - .rspec
195
+ - .travis.yml
196
+ - CODE_OF_CONDUCT.md
197
+ - Gemfile
198
+ - Guardfile
199
+ - LICENSE.txt
200
+ - README.md
201
+ - Rakefile
202
+ - bin/console
203
+ - bin/setup
204
+ - four_o_four.gemspec
205
+ - lib/four_o_four.rb
206
+ homepage: https://github.com/esparta/four_o_four
207
+ licenses:
208
+ - MIT
209
+ metadata: {}
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - '>='
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 2.2.2
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: FourOFour, a simple Rack middleware to handle 404 responses with delegation
230
+ test_files: []