rescuable_errors 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +15 -0
  5. data/Gemfile.lock +169 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.md +37 -0
  8. data/Rakefile +31 -0
  9. data/VERSION +1 -0
  10. data/Vagrantfile +10 -0
  11. data/lib/engine.rb +4 -0
  12. data/lib/rescuable_errors.rb +24 -0
  13. data/lib/rescuable_errors/application_error.rb +5 -0
  14. data/rescuable_errors.gemspec +108 -0
  15. data/spec/dummy/.gitignore +13 -0
  16. data/spec/dummy/Gemfile +43 -0
  17. data/spec/dummy/Gemfile.lock +159 -0
  18. data/spec/dummy/README.rdoc +28 -0
  19. data/spec/dummy/Rakefile +6 -0
  20. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  21. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  22. data/spec/dummy/app/controllers/users_controller.rb +13 -0
  23. data/spec/dummy/app/errors/model_validation_error.rb +9 -0
  24. data/spec/dummy/app/errors/routing_error.rb +8 -0
  25. data/spec/dummy/app/errors/unauthenticated_error.rb +8 -0
  26. data/spec/dummy/bin/bundle +3 -0
  27. data/spec/dummy/bin/rails +8 -0
  28. data/spec/dummy/bin/rake +8 -0
  29. data/spec/dummy/bin/setup +29 -0
  30. data/spec/dummy/bin/spring +15 -0
  31. data/spec/dummy/config.ru +4 -0
  32. data/spec/dummy/config/application.rb +32 -0
  33. data/spec/dummy/config/boot.rb +3 -0
  34. data/spec/dummy/config/environment.rb +5 -0
  35. data/spec/dummy/config/environments/development.rb +38 -0
  36. data/spec/dummy/config/environments/production.rb +76 -0
  37. data/spec/dummy/config/environments/test.rb +42 -0
  38. data/spec/dummy/config/initializers/assets.rb +11 -0
  39. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  41. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/spec/dummy/config/initializers/inflections.rb +16 -0
  43. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  44. data/spec/dummy/config/initializers/rescue.rb +5 -0
  45. data/spec/dummy/config/initializers/session_store.rb +3 -0
  46. data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
  47. data/spec/dummy/config/locales/pt-BR.yml +4 -0
  48. data/spec/dummy/config/routes.rb +10 -0
  49. data/spec/dummy/config/secrets.yml +22 -0
  50. data/spec/dummy/lib/assets/.keep +0 -0
  51. data/spec/dummy/lib/tasks/.keep +0 -0
  52. data/spec/dummy/log/.keep +0 -0
  53. data/spec/rescuable_errors_spec.rb +47 -0
  54. data/spec/spec_helper.rb +31 -0
  55. metadata +182 -0
@@ -0,0 +1,13 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore all logfiles and tempfiles.
11
+ /log/*
12
+ !/log/.keep
13
+ /tmp
@@ -0,0 +1,43 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
+ gem 'rails', '4.2.0'
6
+ # Use SCSS for stylesheets
7
+ gem 'sass-rails', '~> 5.0'
8
+ # Use Uglifier as compressor for JavaScript assets
9
+ gem 'uglifier', '>= 1.3.0'
10
+ # Use CoffeeScript for .coffee assets and views
11
+ gem 'coffee-rails', '~> 4.1.0'
12
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
13
+ # gem 'therubyracer', platforms: :ruby
14
+
15
+ # Use jquery as the JavaScript library
16
+ gem 'jquery-rails'
17
+ # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
18
+ gem 'turbolinks'
19
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
20
+ gem 'jbuilder', '~> 2.0'
21
+ # bundle exec rake doc:rails generates the API under doc/api.
22
+ gem 'sdoc', '~> 0.4.0', group: :doc
23
+
24
+ # Use ActiveModel has_secure_password
25
+ # gem 'bcrypt', '~> 3.1.7'
26
+
27
+ # Use Unicorn as the app server
28
+ # gem 'unicorn'
29
+
30
+ # Use Capistrano for deployment
31
+ # gem 'capistrano-rails', group: :development
32
+
33
+ group :development, :test do
34
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
35
+ gem 'byebug'
36
+
37
+ # Access an IRB console on exception pages or by using <%= console %> in views
38
+ gem 'web-console', '~> 2.0'
39
+
40
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
41
+ gem 'spring'
42
+ end
43
+
@@ -0,0 +1,159 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (4.2.0)
5
+ actionpack (= 4.2.0)
6
+ actionview (= 4.2.0)
7
+ activejob (= 4.2.0)
8
+ mail (~> 2.5, >= 2.5.4)
9
+ rails-dom-testing (~> 1.0, >= 1.0.5)
10
+ actionpack (4.2.0)
11
+ actionview (= 4.2.0)
12
+ activesupport (= 4.2.0)
13
+ rack (~> 1.6.0)
14
+ rack-test (~> 0.6.2)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
17
+ actionview (4.2.0)
18
+ activesupport (= 4.2.0)
19
+ builder (~> 3.1)
20
+ erubis (~> 2.7.0)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
23
+ activejob (4.2.0)
24
+ activesupport (= 4.2.0)
25
+ globalid (>= 0.3.0)
26
+ activemodel (4.2.0)
27
+ activesupport (= 4.2.0)
28
+ builder (~> 3.1)
29
+ activerecord (4.2.0)
30
+ activemodel (= 4.2.0)
31
+ activesupport (= 4.2.0)
32
+ arel (~> 6.0)
33
+ activesupport (4.2.0)
34
+ i18n (~> 0.7)
35
+ json (~> 1.7, >= 1.7.7)
36
+ minitest (~> 5.1)
37
+ thread_safe (~> 0.3, >= 0.3.4)
38
+ tzinfo (~> 1.1)
39
+ arel (6.0.0)
40
+ binding_of_caller (0.7.2)
41
+ debug_inspector (>= 0.0.1)
42
+ builder (3.2.2)
43
+ byebug (4.0.1)
44
+ columnize (= 0.9.0)
45
+ rb-readline (= 0.5.2)
46
+ coffee-rails (4.1.0)
47
+ coffee-script (>= 2.2.0)
48
+ railties (>= 4.0.0, < 5.0)
49
+ coffee-script (2.3.0)
50
+ coffee-script-source
51
+ execjs
52
+ coffee-script-source (1.9.1)
53
+ columnize (0.9.0)
54
+ debug_inspector (0.0.2)
55
+ erubis (2.7.0)
56
+ execjs (2.4.0)
57
+ globalid (0.3.3)
58
+ activesupport (>= 4.1.0)
59
+ hike (1.2.3)
60
+ i18n (0.7.0)
61
+ jbuilder (2.2.11)
62
+ activesupport (>= 3.0.0, < 5)
63
+ multi_json (~> 1.2)
64
+ jquery-rails (4.0.3)
65
+ rails-dom-testing (~> 1.0)
66
+ railties (>= 4.2.0)
67
+ thor (>= 0.14, < 2.0)
68
+ json (1.8.2)
69
+ loofah (2.0.1)
70
+ nokogiri (>= 1.5.9)
71
+ mail (2.6.3)
72
+ mime-types (>= 1.16, < 3)
73
+ mime-types (2.4.3)
74
+ mini_portile (0.6.2)
75
+ minitest (5.5.1)
76
+ multi_json (1.11.0)
77
+ nokogiri (1.6.6.2)
78
+ mini_portile (~> 0.6.0)
79
+ rack (1.6.0)
80
+ rack-test (0.6.3)
81
+ rack (>= 1.0)
82
+ rails (4.2.0)
83
+ actionmailer (= 4.2.0)
84
+ actionpack (= 4.2.0)
85
+ actionview (= 4.2.0)
86
+ activejob (= 4.2.0)
87
+ activemodel (= 4.2.0)
88
+ activerecord (= 4.2.0)
89
+ activesupport (= 4.2.0)
90
+ bundler (>= 1.3.0, < 2.0)
91
+ railties (= 4.2.0)
92
+ sprockets-rails
93
+ rails-deprecated_sanitizer (1.0.3)
94
+ activesupport (>= 4.2.0.alpha)
95
+ rails-dom-testing (1.0.5)
96
+ activesupport (>= 4.2.0.beta, < 5.0)
97
+ nokogiri (~> 1.6.0)
98
+ rails-deprecated_sanitizer (>= 1.0.1)
99
+ rails-html-sanitizer (1.0.2)
100
+ loofah (~> 2.0)
101
+ railties (4.2.0)
102
+ actionpack (= 4.2.0)
103
+ activesupport (= 4.2.0)
104
+ rake (>= 0.8.7)
105
+ thor (>= 0.18.1, < 2.0)
106
+ rake (10.4.2)
107
+ rb-readline (0.5.2)
108
+ rdoc (4.2.0)
109
+ sass (3.4.13)
110
+ sass-rails (5.0.1)
111
+ railties (>= 4.0.0, < 5.0)
112
+ sass (~> 3.1)
113
+ sprockets (>= 2.8, < 4.0)
114
+ sprockets-rails (>= 2.0, < 4.0)
115
+ tilt (~> 1.1)
116
+ sdoc (0.4.1)
117
+ json (~> 1.7, >= 1.7.7)
118
+ rdoc (~> 4.0)
119
+ spring (1.3.3)
120
+ sprockets (2.12.3)
121
+ hike (~> 1.2)
122
+ multi_json (~> 1.0)
123
+ rack (~> 1.0)
124
+ tilt (~> 1.1, != 1.3.0)
125
+ sprockets-rails (2.2.4)
126
+ actionpack (>= 3.0)
127
+ activesupport (>= 3.0)
128
+ sprockets (>= 2.8, < 4.0)
129
+ thor (0.19.1)
130
+ thread_safe (0.3.5)
131
+ tilt (1.4.1)
132
+ turbolinks (2.5.3)
133
+ coffee-rails
134
+ tzinfo (1.2.2)
135
+ thread_safe (~> 0.1)
136
+ uglifier (2.7.1)
137
+ execjs (>= 0.3.0)
138
+ json (>= 1.8.0)
139
+ web-console (2.1.2)
140
+ activemodel (>= 4.0)
141
+ binding_of_caller (>= 0.7.2)
142
+ railties (>= 4.0)
143
+ sprockets-rails (>= 2.0, < 4.0)
144
+
145
+ PLATFORMS
146
+ ruby
147
+
148
+ DEPENDENCIES
149
+ byebug
150
+ coffee-rails (~> 4.1.0)
151
+ jbuilder (~> 2.0)
152
+ jquery-rails
153
+ rails (= 4.2.0)
154
+ sass-rails (~> 5.0)
155
+ sdoc (~> 0.4.0)
156
+ spring
157
+ turbolinks
158
+ uglifier (>= 1.3.0)
159
+ web-console (~> 2.0)
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ class UsersController < ApplicationController
2
+ def unauthenticated
3
+ fail RescuableErrors::UnauthenticatedError.new
4
+ end
5
+
6
+ def routing
7
+ fail RescuableErrors::RoutingError.new
8
+ end
9
+
10
+ def model
11
+ fail RescuableErrors::ModelValidationError.new(Struct.new(:messages).new({:name=>["can't be empty"]}))
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class ModelValidationError < RescuableErrors::ApplicationError
2
+ def initialize(errors)
3
+ @code = 400
4
+ @status = 400
5
+ @class = "RescuableErrors::ModelValidationError"
6
+ super errors.messages.to_json
7
+ end
8
+ end
9
+
@@ -0,0 +1,8 @@
1
+ class RoutingError < RescuableErrors::ApplicationError
2
+ def initialize
3
+ @code = 404
4
+ @status = 404
5
+ @class = "RescuableErrors::RoutingError"
6
+ super I18n.t("errors.routing")
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class UnauthenticatedError < RescuableErrors::ApplicationError
2
+ def initialize
3
+ @code = 401
4
+ @status = 401
5
+ @class = "RescuableErrors::UnauthenticatedError"
6
+ super I18n.t("errors.unauthenticated")
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
7
+ require_relative '../config/boot'
8
+ require 'rails/commands'
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ require_relative '../config/boot'
7
+ require 'rake'
8
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This file loads spring without using Bundler, in order to be fast.
4
+ # It gets overwritten when you run the `spring binstub` command.
5
+
6
+ unless defined?(Spring)
7
+ require "rubygems"
8
+ require "bundler"
9
+
10
+ if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)
11
+ Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq }
12
+ gem "spring", match[1]
13
+ require "spring/binstub"
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_model/railtie"
5
+ require "active_job/railtie"
6
+ # require "active_record/railtie"
7
+ require "action_controller/railtie"
8
+ require "action_mailer/railtie"
9
+ require "action_view/railtie"
10
+ require "sprockets/railtie"
11
+ # require "rails/test_unit/railtie"
12
+
13
+ # Require the gems listed in Gemfile, including any gems
14
+ # you've limited to :test, :development, or :production.
15
+ Bundler.require(*Rails.groups)
16
+
17
+ module Dummy
18
+ class Application < Rails::Application
19
+ # Settings in config/environments/* take precedence over those specified here.
20
+ # Application configuration should go into files in config/initializers
21
+ # -- all .rb files in that directory are automatically loaded.
22
+
23
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
24
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
25
+ # config.time_zone = 'Central Time (US & Canada)'
26
+
27
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
28
+ config.i18n.locale = :'pt-BR'
29
+ config.i18n.available_locales = [:'pt-BR']
30
+ I18n.config.enforce_available_locales = true
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,38 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Debug mode disables concatenation and preprocessing of assets.
23
+ # This option may cause significant delays in view rendering with a large
24
+ # number of complex assets.
25
+ config.assets.debug = true
26
+
27
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
28
+ # yet still be able to expire them through the digest params.
29
+ config.assets.digest = true
30
+
31
+ # Adds additional error checking when serving assets at runtime.
32
+ # Checks for improperly declared sprockets dependencies.
33
+ # Raises helpful error messages.
34
+ config.assets.raise_runtime_errors = true
35
+
36
+ # Raises error for missing translations
37
+ # config.action_view.raise_on_missing_translations = true
38
+ end