not_found_catcher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +39 -0
- data/Rakefile +26 -0
- data/app/assets/config/not_found_catcher_manifest.js +2 -0
- data/app/assets/javascripts/not_found_catcher/application.js +14 -0
- data/app/assets/stylesheets/not_found_catcher/application.css +15 -0
- data/app/controllers/not_found_catcher/application_controller.rb +5 -0
- data/app/controllers/not_found_catcher/exceptions_controller.rb +10 -0
- data/app/controllers/not_found_catcher/roles_controller.rb +49 -0
- data/app/helpers/not_found_catcher/application_helper.rb +4 -0
- data/app/jobs/not_found_catcher/application_job.rb +4 -0
- data/app/lib/not_found_catcher/not_found_route_exception.rb +12 -0
- data/app/lib/not_found_catcher/request_parser.rb +56 -0
- data/app/lib/not_found_catcher/request_store.rb +77 -0
- data/app/mailers/not_found_catcher/application_mailer.rb +6 -0
- data/app/middleware/not_found_catcher/middleware.rb +46 -0
- data/app/models/not_found_catcher/application_record.rb +5 -0
- data/app/models/not_found_catcher/role.rb +32 -0
- data/app/views/layouts/not_found_catcher/application.html.erb +14 -0
- data/app/views/not_found_catcher/roles/edit.html.erb +9 -0
- data/app/views/not_found_catcher/roles/index.html.erb +24 -0
- data/config/routes.rb +13 -0
- data/lib/generators/not_found_catcher/USAGE +8 -0
- data/lib/generators/not_found_catcher/not_found_catcher_generator.rb +13 -0
- data/lib/generators/not_found_catcher/templates/not_found_catcher.rb.erb +33 -0
- data/lib/not_found_catcher/engine.rb +17 -0
- data/lib/not_found_catcher/version.rb +3 -0
- data/lib/not_found_catcher.rb +64 -0
- data/lib/tasks/not_found_catcher_tasks.rake +4 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7991ac97bef725470d70a77ad378e7cbf4f24eeb
|
4
|
+
data.tar.gz: '0051002885918d4274ce36a530edea8dc18e0466'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f9e687d926cbcfcb0895b1f363cc7b501076a552aafe4cf18707e935e39c732874b88ff94f47b4997c7a451093075db508b858f312f2ef4e034a2462a3a1fa5
|
7
|
+
data.tar.gz: be2aeb383e882a90b850193da0eea12ee5e51e8b70ac7151c17c5c4bd0a709cbcc71ab05dfdc9e91c48697117e5a4d3dcb596776b268ac7c594a8b17f80ff7f2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Marino Bonetti
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# NotFoundCatcher
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'not_found_catcher'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Installazione dell'inizializzatore
|
20
|
+
```bash
|
21
|
+
bin/rails g not_found_catcher install
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
After installing go to /not_found_catcher and you will see the administration panel, it's a simple
|
26
|
+
wrapper around the yml file with the configurations.
|
27
|
+
If an error occur of not_found inside the applicaion, the yml file will be populated.
|
28
|
+
You can define simple redirects matching exat the value, or you can use regexp to catch more errors and
|
29
|
+
redirect these to logic redirects:
|
30
|
+
|
31
|
+
/category/(.*) => http://example.com?category=$1
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
Contribution directions go here.
|
37
|
+
|
38
|
+
## License
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'NotFoundCatcher'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
14
|
+
//= require rails-ujs
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module NotFoundCatcher
|
2
|
+
class RolesController < NotFoundCatcher::ApplicationController
|
3
|
+
|
4
|
+
before_action :load_object, only: [:edit, :update, :destroy]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@store = NotFoundCatcher.request_store
|
8
|
+
end
|
9
|
+
|
10
|
+
def edit
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
@obj.assign_attributes(params.require(:role).permit(:role, :method, :redirect))
|
15
|
+
|
16
|
+
|
17
|
+
respond_to do |f|
|
18
|
+
|
19
|
+
if @obj.valid?
|
20
|
+
|
21
|
+
@obj.save
|
22
|
+
f.html {redirect_to root_path}
|
23
|
+
else
|
24
|
+
render :edit
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy
|
32
|
+
respond_to do |f|
|
33
|
+
|
34
|
+
if @obj.destroy
|
35
|
+
f.html {redirect_to root_path}
|
36
|
+
else
|
37
|
+
render :edit
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def load_object
|
45
|
+
@obj = NotFoundCatcher.request_store.find(params[:id]).model
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module NotFoundCatcher
|
2
|
+
class RequestParser < Struct.new(:role, :method, :redirect)
|
3
|
+
|
4
|
+
|
5
|
+
def considered?
|
6
|
+
!redirect.blank?
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_redirect(request)
|
10
|
+
|
11
|
+
request.fullpath.gsub(Regexp.new(self.role),self.redirect.gsub(/\$([0-9]+)/,'$$$1').gsub('$$$','\\'))
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Return the relative model for this record
|
17
|
+
def model
|
18
|
+
|
19
|
+
r = Role.new(
|
20
|
+
role: self.role,
|
21
|
+
http_method: self.method,
|
22
|
+
redirect: self.redirect
|
23
|
+
)
|
24
|
+
r.request_parser = self
|
25
|
+
r
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
##
|
31
|
+
# Cerca se stesso all'interno dello store e si salva
|
32
|
+
def save
|
33
|
+
store = NotFoundCatcher.request_store.store
|
34
|
+
store.transaction do
|
35
|
+
|
36
|
+
store[self.role] = self
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def id
|
44
|
+
Digest::MD5.hexdigest(self.role)
|
45
|
+
end
|
46
|
+
|
47
|
+
def destroy
|
48
|
+
store = NotFoundCatcher.request_store.store
|
49
|
+
store.transaction do
|
50
|
+
store.delete(self.role)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'yaml/store'
|
2
|
+
class NotFoundCatcher::RequestStore
|
3
|
+
|
4
|
+
attr_accessor :path
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
self.path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def parse(request)
|
12
|
+
|
13
|
+
key = get_first_match(request.fullpath)
|
14
|
+
|
15
|
+
store.transaction do
|
16
|
+
|
17
|
+
if key
|
18
|
+
req = store[key]
|
19
|
+
else
|
20
|
+
req = store[request.fullpath] = NotFoundCatcher::RequestParser.new(request.fullpath, request.request_method, nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
yield req
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Restituisce la prima chiave matchata
|
32
|
+
def get_first_match(path)
|
33
|
+
|
34
|
+
store.transaction(true) do
|
35
|
+
|
36
|
+
store.roots.each do |k|
|
37
|
+
|
38
|
+
if path.match(k)
|
39
|
+
return k
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
def each
|
48
|
+
|
49
|
+
store.transaction(true) do
|
50
|
+
|
51
|
+
store.roots.each do |k|
|
52
|
+
|
53
|
+
yield store[k]
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def find(key)
|
62
|
+
rule = nil
|
63
|
+
store.transaction(true) do
|
64
|
+
store.roots.each do |k|
|
65
|
+
rule = store[k] if store[k].id == key
|
66
|
+
end
|
67
|
+
end
|
68
|
+
rule
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# Store yaml
|
73
|
+
def store
|
74
|
+
@_store ||= YAML::Store.new self.path
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module NotFoundCatcher
|
2
|
+
class Middleware
|
3
|
+
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def exceptions_to_catch
|
9
|
+
@_exceptions_to_catch ||= NotFoundCatcher.exceptions_to_catch.collect {|v| v.is_a?(String) ? v.constantize : v}
|
10
|
+
end
|
11
|
+
|
12
|
+
def redirect_to(location, content_type: 'text/html', status: 301)
|
13
|
+
[status, {'Location' => location, 'Content-Type' => content_type}, ['Moved Permanently']]
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
begin
|
18
|
+
ris = @app.call(env)
|
19
|
+
rescue *exceptions_to_catch
|
20
|
+
|
21
|
+
begin
|
22
|
+
rs = NotFoundCatcher.request_store
|
23
|
+
request = ActionDispatch::Request.new(env)
|
24
|
+
|
25
|
+
rs.parse(request) do |req|
|
26
|
+
|
27
|
+
if req.considered?
|
28
|
+
redirect_path = req.build_redirect(request)
|
29
|
+
Rails.logger.info {"[NOT_FOUND_CATCHER] Catch #{request.fullpath} -> #{redirect_path}"}
|
30
|
+
ris = redirect_to redirect_path
|
31
|
+
else
|
32
|
+
Rails.logger.info {"[NOT_FOUND_CATCHER] Catch non gestito:#{request.fullpath}"}
|
33
|
+
ris = redirect_to NotFoundCatcher.if_not_considered_path.call(request), status: 302
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
rescue Exception => e
|
38
|
+
Rails.logger.info {"[NOT_FOUND_CATCHER] Problemi - #{e.message} - #{e.backtrace.join("\n")}"}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
ris
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module NotFoundCatcher
|
2
|
+
class Role < ActiveType::Object
|
3
|
+
|
4
|
+
attr_accessor :request_parser
|
5
|
+
|
6
|
+
attribute :role, :string
|
7
|
+
attribute :http_method, :string
|
8
|
+
attribute :redirect, :string
|
9
|
+
|
10
|
+
|
11
|
+
def persisted?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def id
|
16
|
+
self.request_parser.id
|
17
|
+
end
|
18
|
+
|
19
|
+
def save
|
20
|
+
|
21
|
+
request_parser.role = self.role
|
22
|
+
request_parser.method = self.http_method
|
23
|
+
request_parser.redirect = self.redirect
|
24
|
+
|
25
|
+
request_parser.save
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
delegate :destroy,to: :request_parser
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Not found catcher</title>
|
5
|
+
<%= stylesheet_link_tag "not_found_catcher/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "not_found_catcher/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<table border="1">
|
2
|
+
<tr>
|
3
|
+
<th>Rule</th>
|
4
|
+
<th>Method</th>
|
5
|
+
<th>Redirect</th>
|
6
|
+
<th></th>
|
7
|
+
</tr>
|
8
|
+
|
9
|
+
|
10
|
+
<% @store.each do |row| %>
|
11
|
+
|
12
|
+
<tr>
|
13
|
+
<td><%= row.role %></td>
|
14
|
+
<td><%= row.method %></td>
|
15
|
+
<td><%= row.redirect %></td>
|
16
|
+
<td>
|
17
|
+
<%= link_to 'edit', edit_role_path(row.id) %>
|
18
|
+
<%= link_to 'destroy', role_path(row.id), method: :delete, data: {confirm: "Are you sure?"} %>
|
19
|
+
</td>
|
20
|
+
</tr>
|
21
|
+
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
</table>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
NotFoundCatcher::Engine.routes.draw do
|
2
|
+
|
3
|
+
resources :roles, only: [:index, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
root to: 'roles#index'
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
##
|
10
|
+
# Appendo una rotta finale per matchare tutto quello sbagliato
|
11
|
+
Rails.application.routes.append do
|
12
|
+
match '*path', controller: 'not_found_catcher/exceptions', action: :show, via: [:get, :post, :put, :delete]
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class NotFoundCatcherGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def create_initializer
|
5
|
+
copy_file 'not_found_catcher.rb.erb', 'config/initializers/not_found_catcher.rb'
|
6
|
+
end
|
7
|
+
|
8
|
+
def install_routes
|
9
|
+
route 'mount NotFoundCatcher::Engine => "/not_found_catcher"'
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
NotFoundCatcher.setup do |c|
|
2
|
+
|
3
|
+
# Posizione del file yml per salvare lo stato dei redirects
|
4
|
+
# c.request_db= -> {Rails.root.join('config', 'page_not_found.yml')}
|
5
|
+
|
6
|
+
# Redirect nel caso non abbiamo nessun match o regola di redirect nel DB
|
7
|
+
# c.if_not_considered_path = ->(env){ Rails.application.routes.url_helpers.root_path }
|
8
|
+
|
9
|
+
##
|
10
|
+
# Se siamo in sviluppo e questa configurazione è a true, tutte le richieste non saranno locali
|
11
|
+
# altrimenti seguono lo standard della configurazione dell'applicativo
|
12
|
+
# c.dev_mode=false
|
13
|
+
|
14
|
+
|
15
|
+
##
|
16
|
+
# Controller da cui derivare il lato amministrativo dell'engine
|
17
|
+
#c.base_admin_controller = "ActionController::Base"
|
18
|
+
|
19
|
+
|
20
|
+
##
|
21
|
+
# Controller da cui derivare il lato catch_all delle chiamate
|
22
|
+
# c.base_catcher_controller = "ActionController::Base"
|
23
|
+
|
24
|
+
|
25
|
+
##
|
26
|
+
# Catcher attivo o meno, utile per quando si è in sviluppo
|
27
|
+
c.enabled = Rails.env.production?
|
28
|
+
|
29
|
+
##
|
30
|
+
# Elenco degli errori da ascoltare
|
31
|
+
# c.exceptions_to_catch << Exception # to catch all
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module NotFoundCatcher
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace NotFoundCatcher
|
4
|
+
|
5
|
+
require 'active_type'
|
6
|
+
|
7
|
+
# initializer 'not_found_catcher.set_error_catcher', before: "better_errors.configure_rails_initialization" do |app|
|
8
|
+
# app.config.exceptions_app = ->(env) {NotFoundCatcher::ExceptionsController.action(:show).call(env)}
|
9
|
+
# app.config.consider_all_requests_local = !NotFoundCatcher.dev_mode if Rails.env.development?
|
10
|
+
# end
|
11
|
+
|
12
|
+
initializer 'not_found_catcher.set_error_catcher_middleware' do |app|
|
13
|
+
app.config.middleware.use NotFoundCatcher::Middleware
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "not_found_catcher/engine"
|
2
|
+
module NotFoundCatcher
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
|
5
|
+
autoload :RequestStore
|
6
|
+
autoload :RequestParser
|
7
|
+
|
8
|
+
##
|
9
|
+
# Posizione del file yml in cui registrare tutte le richieste andate male
|
10
|
+
# e le possibili risoluzioni
|
11
|
+
mattr_accessor :request_db
|
12
|
+
@@request_db = -> {Rails.root.join('config', 'page_not_found.yml')}
|
13
|
+
|
14
|
+
|
15
|
+
def self.request_store
|
16
|
+
@_req_st ||= (
|
17
|
+
path = NotFoundCatcher.request_db.()
|
18
|
+
FileUtils.touch path unless File.exists?(path)
|
19
|
+
|
20
|
+
RequestStore.new(path)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Controller da cui derivare il lato amministrativo dell'engine
|
26
|
+
mattr_accessor :base_admin_controller
|
27
|
+
@@base_admin_controller = "ActionController::Base"
|
28
|
+
|
29
|
+
|
30
|
+
##
|
31
|
+
# Controller da cui derivare il lato catch_all delle chiamate
|
32
|
+
mattr_accessor :base_catcher_controller
|
33
|
+
@@base_catcher_controller = "ActionController::Base"
|
34
|
+
|
35
|
+
|
36
|
+
##
|
37
|
+
# Se siamo in sviluppo e questa configurazione è a true, tutte le richieste non saranno locali
|
38
|
+
# altrimenti seguono lo standard della configurazione dell'applicativo
|
39
|
+
mattr_accessor :dev_mode
|
40
|
+
@@dev_mode = false
|
41
|
+
|
42
|
+
# Redirect nel caso non abbiamo nessun match o regola di redirect nel DB
|
43
|
+
mattr_accessor :if_not_considered_path
|
44
|
+
@@if_not_considered_path = ->(env) {Rails.application.routes.url_helpers.root_path}
|
45
|
+
|
46
|
+
|
47
|
+
##
|
48
|
+
# Elenco degli errori da ascoltare
|
49
|
+
mattr_accessor :exceptions_to_catch
|
50
|
+
@@exceptions_to_catch = ['NotFoundCatcher::NotFoundRouteException']
|
51
|
+
|
52
|
+
##
|
53
|
+
# Catcher attivo o meno, utile per quando si è in sviluppo
|
54
|
+
mattr_accessor :enabled
|
55
|
+
@@enabled = true
|
56
|
+
|
57
|
+
# Default way to setup TikalCore. Run "rails generate tikal_core_install" to create
|
58
|
+
# a fresh initializer with all configuration values.
|
59
|
+
def self.setup
|
60
|
+
yield self
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: not_found_catcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marino Bonetti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.1'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: active_type
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sqlite3
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
description: 'Mountable Engine to catch not_found_errors and to administrate redirects '
|
62
|
+
email:
|
63
|
+
- marinobonetti@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- MIT-LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- app/assets/config/not_found_catcher_manifest.js
|
72
|
+
- app/assets/javascripts/not_found_catcher/application.js
|
73
|
+
- app/assets/stylesheets/not_found_catcher/application.css
|
74
|
+
- app/controllers/not_found_catcher/application_controller.rb
|
75
|
+
- app/controllers/not_found_catcher/exceptions_controller.rb
|
76
|
+
- app/controllers/not_found_catcher/roles_controller.rb
|
77
|
+
- app/helpers/not_found_catcher/application_helper.rb
|
78
|
+
- app/jobs/not_found_catcher/application_job.rb
|
79
|
+
- app/lib/not_found_catcher/not_found_route_exception.rb
|
80
|
+
- app/lib/not_found_catcher/request_parser.rb
|
81
|
+
- app/lib/not_found_catcher/request_store.rb
|
82
|
+
- app/mailers/not_found_catcher/application_mailer.rb
|
83
|
+
- app/middleware/not_found_catcher/middleware.rb
|
84
|
+
- app/models/not_found_catcher/application_record.rb
|
85
|
+
- app/models/not_found_catcher/role.rb
|
86
|
+
- app/views/layouts/not_found_catcher/application.html.erb
|
87
|
+
- app/views/not_found_catcher/roles/edit.html.erb
|
88
|
+
- app/views/not_found_catcher/roles/index.html.erb
|
89
|
+
- config/routes.rb
|
90
|
+
- lib/generators/not_found_catcher/USAGE
|
91
|
+
- lib/generators/not_found_catcher/not_found_catcher_generator.rb
|
92
|
+
- lib/generators/not_found_catcher/templates/not_found_catcher.rb.erb
|
93
|
+
- lib/not_found_catcher.rb
|
94
|
+
- lib/not_found_catcher/engine.rb
|
95
|
+
- lib/not_found_catcher/version.rb
|
96
|
+
- lib/tasks/not_found_catcher_tasks.rake
|
97
|
+
homepage: http://gitbuh.com/oniram88/NotFoundCatcher
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.5.2
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Mountable Engine to catch not_found_errors and to administrate redirects
|
121
|
+
test_files: []
|