jt-rails-toolbox 1.2.4 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eff5152abcc01c7e0debdc49f6c2f3457f5f1a49
4
- data.tar.gz: d8e377177778f27d9368bcdccfdc408bdc880efa
3
+ metadata.gz: a45f1dfd078655bd41b9d50cd255a8f555634517
4
+ data.tar.gz: 2cd6dd09ad2b11d32028ff2401015ea4443b0ffc
5
5
  SHA512:
6
- metadata.gz: 713555745af64e4299e7ef09c54f7e23badd6f6f47b1711564de35eec1e9ff49bd880c3253cde8281c710192050c5dd6f23d779f59aebb367a9546809483c831
7
- data.tar.gz: 73daaf71a69f27ef11037b481aa9bdb4bbc5d4761616783ff978bd486966e970d453f68fa1bad4ec56e9501de4b7cb50d63ecdc2be00345ce9ee3e45b4194883
6
+ metadata.gz: 5723b4572f6d42a438399a7cce0d12190d813cd28a02dc2ed2dee64c65dd3e3c1bd7430571b5382633d5f8b7d5782177befccbe99b22b5a685b39fb18f641487
7
+ data.tar.gz: 54fbfdb5fab2546e7454c9cc5e0f7ed2d6b8df40b0c309b884f0ba2b806c0499d967ad3b30242bd9a507162b55f9f911b66944d37d4ea7ff5115041b0c62adc8
data/README.md CHANGED
@@ -21,6 +21,12 @@ A simple configuration of `jt-toolbox.yml` file:
21
21
  ```yml
22
22
  production:
23
23
  exception:
24
+ airbrake:
25
+ project_host: "https://errbit.example.com"
26
+ project_id: 1
27
+ project_key: 12345678901234567890
28
+ slack:
29
+ webhook_url: https://hooks.slack.com/services/XXXXXXXX
24
30
  email_prefix: '[ERROR]'
25
31
  sender_address: "Your website <error@example.com>"
26
32
  exception_recipients:
@@ -48,7 +54,11 @@ A simple configuration of `jt-toolbox.yml` file:
48
54
 
49
55
  ## What's in it?
50
56
 
51
- - [Exception Notification](https://github.com/smartinez87/exception_notification), send email notifications when errors occur
57
+ - [http_accept_language](https://github.com/iain/http_accept_language), helps you detect the users preferred language, as sent by the "Accept-Language" HTTP header
58
+ - [dotenv](https://github.com/bkeepers/dotenv), load environment variables from .env file
59
+ - [Exception Notification](https://github.com/smartinez87/exception_notification),
60
+ send notifications when errors occur (email, slack)
61
+ - [Airbrake](https://github.com/airbrake/airbrake), send notifications when errors occur to [Airbrake](https://airbrake.io/) or [Errbit](http://errbit.com/)
52
62
  - [paperclip](https://github.com/thoughtbot/paperclip), manage file upload
53
63
  - [quiet_assets](https://github.com/evrone/quiet_assets), silence assets in log
54
64
  - [sidekiq](https://github.com/mperham/sidekiq), manage background jobs
@@ -59,6 +69,21 @@ A simple configuration of `jt-toolbox.yml` file:
59
69
  - [jt-rails-tokenizable](https://github.com/jonathantribouharet/jt-rails-tokenizable) Generate tokens for ActiveRecord models
60
70
  - simplified configuration of hostnames and `ActionMailer` with a YAML file
61
71
 
72
+ ### http_accept_language
73
+
74
+ To install `http_accept_language` you just have to add a line in your `ApplicationController`
75
+
76
+ ```ruby
77
+ class ApplicationController < ActionController::Base
78
+ include HttpAcceptLanguage::AutoLocale
79
+
80
+ end
81
+ ```
82
+
83
+ ### Dotenv
84
+
85
+ It's a good practice to not include credentials for third party services in your code. You can defined it in a `.env` file which I recommend to not include in your git repository.
86
+
62
87
  ### Exception Notification
63
88
 
64
89
  If `exception` is not set in `jt-toolbox.yml` file, Exception Notification is disabled.
@@ -67,6 +92,10 @@ In addition to the default ignored exceptions, the following exceptions are also
67
92
  - `ActionController::InvalidCrossOriginRequest`
68
93
  - `ActionController::InvalidAuthenticityToken`
69
94
 
95
+ ### Airbrake
96
+
97
+ If `airbrake` is not set in `jt-toolbox.yml` file, Airbrake is disabled.
98
+
70
99
  ### Paperclip
71
100
 
72
101
  - `convert_options` is set to `-strip`, which means all metadata of images are removed, this is used for reduced the weight of images.
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
3
3
  s.summary = "Common libs used for Ruby On Rails development."
4
4
  s.description = "JTRailsToolbox contains a list of common libs used for Ruby On Rails development."
5
5
  s.homepage = 'https://github.com/jonathantribouharet/jt-rails-toolbox'
6
- s.version = '1.2.4'
6
+ s.version = '1.3.0'
7
7
  s.files = `git ls-files`.split("\n")
8
8
  s.require_paths = ['lib']
9
9
  s.authors = ['Jonathan TRIBOUHARET']
@@ -11,7 +11,12 @@ Gem::Specification.new do |s|
11
11
  s.license = 'MIT'
12
12
  s.platform = Gem::Platform::RUBY
13
13
 
14
+ s.add_dependency('dotenv-rails')
15
+ s.add_dependency('http_accept_language')
16
+
14
17
  s.add_dependency('exception_notification', '~> 4.1')
18
+ s.add_dependency('airbrake', '~> 5.0')
19
+
15
20
  s.add_dependency('paperclip', '~> 4.2')
16
21
  s.add_dependency('quiet_assets', '~> 1.1')
17
22
  s.add_dependency('validates_email_format_of', '~> 1.6')
@@ -12,10 +12,16 @@
12
12
  #
13
13
  # production:
14
14
  # exception:
15
+ # airbrake:
16
+ # project_host: "https://errbit.example.com"
17
+ # project_id: 1
18
+ # project_key: 12345678901234567890
19
+ # slack:
20
+ # webhook_url: https://hooks.slack.com/services/XXXXXXXX
15
21
  # email_prefix: '[ERROR]'
16
22
  # sender_address: "Your website <error@example.com>"
17
23
  # exception_recipients:
18
- # - my_email_for_errors@example.com
24
+ # - my_email_for_errors@example.com
19
25
  # files:
20
26
  # folder: upload
21
27
  # mail:
@@ -1,4 +1,5 @@
1
- require 'exception_notification'
1
+ require 'dotenv/rails-now'
2
+ require 'http_accept_language'
2
3
  require 'paperclip'
3
4
  require 'sidekiq'
4
5
  require 'validates_email_format_of'
@@ -7,18 +8,19 @@ require 'jt-rails-meta'
7
8
  require 'jt-rails-generator-user'
8
9
  require 'jt-rails-tokenizable'
9
10
 
11
+ require 'yaml'
12
+
10
13
  if Rails.env.development?
11
14
  require 'quiet_assets'
12
15
  end
13
16
 
14
- require 'exception_notification/rails'
15
- require 'exception_notification/sidekiq'
16
-
17
- require 'yaml'
17
+ # Don't move this require
18
+ require 'airbrake'
19
+ require 'airbrake/sidekiq/error_handler'
18
20
 
19
21
  module JTRailsToolbox
20
22
 
21
- class Railtie < ::Rails::Railtie
23
+ class Engine < ::Rails::Engine
22
24
 
23
25
  initializer "jt-rails-toolbox" do |app|
24
26
  @params = {}
@@ -76,14 +78,58 @@ module JTRailsToolbox
76
78
  def configure_exception_notification(app)
77
79
  return if @params['exception'].nil?
78
80
 
81
+ if @params['exception']['airbrake']
82
+
83
+ Airbrake.configure do |c|
84
+ if @params['exception']['airbrake']['host']
85
+ c.host = @params['exception']['airbrake']['host']
86
+ end
87
+
88
+ c.project_id = @params['exception']['airbrake']['project_id']
89
+ c.project_key = @params['exception']['airbrake']['project_key']
90
+
91
+ c.environment = Rails.env
92
+
93
+ if @params['exception']['airbrake']['ignore_environments']
94
+ c.ignore_environments = @params['exception']['airbrake']['ignore_environments']
95
+ else
96
+ c.ignore_environments = %w(development test)
97
+ end
98
+ end
99
+
100
+ # Default ignored exceptions in Exception Notification
101
+ exceptions_to_ignore = %w{ActiveRecord::RecordNotFound Mongoid::Errors::DocumentNotFound AbstractController::ActionNotFound ActionController::RoutingError ActionController::UnknownFormat ActionController::UrlGenerationError}
102
+
103
+ # Additionnal exceptions to ignore
104
+ exceptions_to_ignore.push *%w{ActionController::InvalidCrossOriginRequest ActionController::InvalidAuthenticityToken}
105
+
106
+ Airbrake.add_filter do |notice|
107
+ if notice[:errors].any? { |error| exceptions_to_ignore.include?(error[:type]) }
108
+ notice.ignore!
109
+ end
110
+ end
111
+ end
112
+
113
+ require 'exception_notification'
114
+ require 'exception_notification/rails'
115
+ require 'exception_notification/sidekiq'
116
+
79
117
  ExceptionNotification.configure do |config|
80
- config.ignored_exceptions += ['ActionController::InvalidCrossOriginRequest', 'ActionController::InvalidAuthenticityToken']
118
+ config.ignored_exceptions += %w{ActionController::InvalidCrossOriginRequest ActionController::InvalidAuthenticityToken}
81
119
 
82
- config.add_notifier :email, {
83
- email_prefix: @params['exception']['email_prefix'],
84
- sender_address: @params['exception']['sender_address'],
85
- exception_recipients: @params['exception']['exception_recipients']
86
- }
120
+ if @params['exception']['slack']
121
+ config.add_notifier :slack, {
122
+ webhook_url: params['exception']['slack']['webhook_url'],
123
+ }
124
+ end
125
+
126
+ if @params['exception']['exception_recipients']
127
+ config.add_notifier :email, {
128
+ email_prefix: @params['exception']['email_prefix'],
129
+ sender_address: @params['exception']['sender_address'],
130
+ exception_recipients: @params['exception']['exception_recipients']
131
+ }
132
+ end
87
133
  end
88
134
  end
89
135
 
@@ -114,8 +160,6 @@ module JTRailsToolbox
114
160
  def configure_sidekiq(app)
115
161
  Sidekiq.configure_server do |config|
116
162
  config.redis = { url: @params['sidekiq']['redis_url'], namespace: @params['sidekiq']['namespace'] }
117
-
118
- config.error_handlers << Proc.new {|ex, ctx_hash| ExceptionNotifier.notify_exception(ex, data: ctx_hash) }
119
163
  end
120
164
 
121
165
  Sidekiq.configure_client do |config|
@@ -126,5 +170,5 @@ module JTRailsToolbox
126
170
  end
127
171
 
128
172
  end
129
-
173
+
130
174
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jt-rails-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan TRIBOUHARET
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-19 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv-rails
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: http_accept_language
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'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: exception_notification
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +52,20 @@ dependencies:
24
52
  - - ~>
25
53
  - !ruby/object:Gem::Version
26
54
  version: '4.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: airbrake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: paperclip
29
71
  requirement: !ruby/object:Gem::Requirement