jt-rails-toolbox 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -4
- data/jt-rails-toolbox.gemspec +6 -1
- data/lib/generators/jt/toolbox/templates/jt-toolbox.yml +5 -0
- data/lib/jt-rails-toolbox.rb +43 -11
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 844f258e0659fee463d6ea2465a283bb42402cb6
|
4
|
+
data.tar.gz: 3b8145a50885a5c2eb5a7051c41a4aa107b632f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b649badbb99452621dec6a1c8371baab5b2f914b4887bb3b7af98cd9ea85d99f3dc120c74eb25b683e95a1d207a85d6aea722eca5c27a00cb5f803e73387a011
|
7
|
+
data.tar.gz: f246dfd58a8c606d633e8413c7762320a82bae9d6135fe9bb5e3584bb99522a1ad499c2e64b42b4638f2c61419aba414737f40dc9747920776394b64aa286598
|
data/README.md
CHANGED
@@ -10,17 +10,22 @@ JTRailsToolbox is distributed as a gem, which is how it should be used in your a
|
|
10
10
|
|
11
11
|
Include the gem in your Gemfile:
|
12
12
|
|
13
|
-
|
13
|
+
gem 'jt-rails-toolbox', '~> 2.0'
|
14
14
|
|
15
15
|
Create a `jt-toolbox.yml` file:
|
16
16
|
|
17
|
-
|
17
|
+
rails g jt:toolbox
|
18
18
|
|
19
19
|
A simple configuration of `jt-toolbox.yml` file:
|
20
20
|
|
21
21
|
```yml
|
22
22
|
production:
|
23
|
+
airbrake:
|
24
|
+
project_host: "https://errbit.example.com"
|
25
|
+
project_id: 1
|
26
|
+
project_key: 12345678901234567890
|
23
27
|
exception:
|
28
|
+
slack_webhook_url: https://hooks.slack.com/services/XXXXXXXX
|
24
29
|
email_prefix: '[ERROR]'
|
25
30
|
sender_address: "Your website <error@example.com>"
|
26
31
|
exception_recipients:
|
@@ -48,7 +53,11 @@ A simple configuration of `jt-toolbox.yml` file:
|
|
48
53
|
|
49
54
|
## What's in it?
|
50
55
|
|
51
|
-
- [
|
56
|
+
- [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
|
57
|
+
- [dotenv](https://github.com/bkeepers/dotenv), load environment variables from .env file
|
58
|
+
- [Exception Notification](https://github.com/smartinez87/exception_notification),
|
59
|
+
send notifications when errors occur (email, slack)
|
60
|
+
- [Airbrake](https://github.com/airbrake/airbrake), send notifications when errors occur to [Airbrake](https://airbrake.io/) or [Errbit](http://errbit.com/)
|
52
61
|
- [paperclip](https://github.com/thoughtbot/paperclip), manage file upload
|
53
62
|
- [sidekiq](https://github.com/mperham/sidekiq), manage background jobs
|
54
63
|
- [validates_email_format_of](https://github.com/validates-email-format-of/validates_email_format_of), who doesn't need to validate email format?
|
@@ -59,6 +68,21 @@ A simple configuration of `jt-toolbox.yml` file:
|
|
59
68
|
- simplified configuration of hostnames and `ActionMailer` with a YAML file
|
60
69
|
- some helper methods
|
61
70
|
|
71
|
+
### http_accept_language
|
72
|
+
|
73
|
+
To install `http_accept_language` you just have to add a line in your `ApplicationController`
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
class ApplicationController < ActionController::Base
|
77
|
+
include HttpAcceptLanguage::AutoLocale
|
78
|
+
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
### Dotenv
|
83
|
+
|
84
|
+
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.
|
85
|
+
|
62
86
|
### Exception Notification
|
63
87
|
|
64
88
|
If `exception` is not set in `jt-toolbox.yml` file, Exception Notification is disabled.
|
@@ -67,6 +91,10 @@ In addition to the default ignored exceptions, the following exceptions are also
|
|
67
91
|
- `ActionController::InvalidCrossOriginRequest`
|
68
92
|
- `ActionController::InvalidAuthenticityToken`
|
69
93
|
|
94
|
+
### Airbrake
|
95
|
+
|
96
|
+
If `airbrake` is not set in `jt-toolbox.yml` file, Airbrake is disabled.
|
97
|
+
|
70
98
|
### Paperclip
|
71
99
|
|
72
100
|
- `convert_options` is set to `-strip`, which means all metadata of images are removed, this is used for reduced the weight of images.
|
@@ -76,7 +104,7 @@ In addition to the default ignored exceptions, the following exceptions are also
|
|
76
104
|
### Sidekiq
|
77
105
|
|
78
106
|
- configured for `ActiveJob`
|
79
|
-
- configured to send notification error with Exception Notification
|
107
|
+
- configured to send notification error with Exception Notification or Airbrake
|
80
108
|
- redis url is by default `redis://localhost:6379/0` and the namespace is `#{name of your application}` for production and `#{name of your application}-{environment}` for others.
|
81
109
|
|
82
110
|
#### Warning
|
data/jt-rails-toolbox.gemspec
CHANGED
@@ -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 = '2.
|
6
|
+
s.version = '2.2.0'
|
7
7
|
s.files = `git ls-files`.split("\n")
|
8
8
|
s.require_paths = ['lib']
|
9
9
|
s.authors = ['Jonathan TRIBOUHARET']
|
@@ -12,8 +12,13 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.platform = Gem::Platform::RUBY
|
13
13
|
|
14
14
|
s.add_dependency('rails', '~> 5.0')
|
15
|
+
|
16
|
+
s.add_dependency('dotenv-rails')
|
17
|
+
s.add_dependency('http_accept_language')
|
15
18
|
|
16
19
|
s.add_dependency('exception_notification', '~> 4.1')
|
20
|
+
s.add_dependency('airbrake', '~> 5.0')
|
21
|
+
|
17
22
|
s.add_dependency('paperclip', '~> 4.2')
|
18
23
|
s.add_dependency('validates_email_format_of', '~> 1.6')
|
19
24
|
s.add_dependency('rails-i18n', '~> 4.0')
|
@@ -11,7 +11,12 @@
|
|
11
11
|
# redis_url: redis://localhost:6379/nameoftheapp
|
12
12
|
#
|
13
13
|
# production:
|
14
|
+
# airbrake:
|
15
|
+
# project_host: "https://errbit.example.com"
|
16
|
+
# project_id: 1
|
17
|
+
# project_key: 12345678901234567890
|
14
18
|
# exception:
|
19
|
+
# slack_webhook_url: https://hooks.slack.com/services/XXXXXXXX
|
15
20
|
# email_prefix: '[ERROR]'
|
16
21
|
# sender_address: "Your website <error@example.com>"
|
17
22
|
# exception_recipients:
|
data/lib/jt-rails-toolbox.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
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,9 +8,6 @@ require 'jt-rails-meta'
|
|
7
8
|
require 'jt-rails-generator-user'
|
8
9
|
require 'jt-rails-tokenizable'
|
9
10
|
|
10
|
-
require 'exception_notification/rails'
|
11
|
-
require 'exception_notification/sidekiq'
|
12
|
-
|
13
11
|
require 'yaml'
|
14
12
|
|
15
13
|
module JTRailsToolbox
|
@@ -28,6 +26,7 @@ module JTRailsToolbox
|
|
28
26
|
|
29
27
|
process_params
|
30
28
|
configure_exception_notification(app)
|
29
|
+
configure_airbrake(app)
|
31
30
|
configure_mail(app)
|
32
31
|
configure_paperclip(app)
|
33
32
|
configure_sidekiq(app)
|
@@ -72,14 +71,49 @@ module JTRailsToolbox
|
|
72
71
|
def configure_exception_notification(app)
|
73
72
|
return if @params['exception'].nil?
|
74
73
|
|
74
|
+
require 'exception_notification'
|
75
|
+
require 'exception_notification/rails'
|
76
|
+
require 'exception_notification/sidekiq'
|
77
|
+
|
75
78
|
ExceptionNotification.configure do |config|
|
76
79
|
config.ignored_exceptions += ['ActionController::InvalidCrossOriginRequest', 'ActionController::InvalidAuthenticityToken']
|
77
80
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
if !@params['exception']['slack_webhook_url'].blank?
|
82
|
+
config.add_notifier :slack, {
|
83
|
+
webhook_url: params['exception']['slack_webhook_url'],
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
if @params['exception']['exception_recipients']
|
88
|
+
config.add_notifier :email, {
|
89
|
+
email_prefix: @params['exception']['email_prefix'],
|
90
|
+
sender_address: @params['exception']['sender_address'],
|
91
|
+
exception_recipients: @params['exception']['exception_recipients']
|
92
|
+
}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def configure_airbrake(app)
|
98
|
+
return if @params['airbrake'].nil?
|
99
|
+
|
100
|
+
require 'airbrake'
|
101
|
+
require 'airbrake/sidekiq/error_handler'
|
102
|
+
|
103
|
+
Airbrake.configure do |c|
|
104
|
+
if @params['airbrake']['host']
|
105
|
+
c.host = @params['airbrake']['host']
|
106
|
+
end
|
107
|
+
|
108
|
+
c.project_id = @params['airbrake']['project_id']
|
109
|
+
c.project_key = @params['airbrake']['project_key']
|
110
|
+
c.environment = Rails.env
|
111
|
+
|
112
|
+
if @params['airbrake']['ignore_environments']
|
113
|
+
c.ignore_environments = @params['airbrake']['ignore_environments']
|
114
|
+
else
|
115
|
+
c.ignore_environments = %w(development test)
|
116
|
+
end
|
83
117
|
end
|
84
118
|
end
|
85
119
|
|
@@ -110,8 +144,6 @@ module JTRailsToolbox
|
|
110
144
|
def configure_sidekiq(app)
|
111
145
|
Sidekiq.configure_server do |config|
|
112
146
|
config.redis = { url: @params['sidekiq']['redis_url'], namespace: @params['sidekiq']['namespace'] }
|
113
|
-
|
114
|
-
config.error_handlers << Proc.new {|ex, ctx_hash| ExceptionNotifier.notify_exception(ex, data: ctx_hash) }
|
115
147
|
end
|
116
148
|
|
117
149
|
Sidekiq.configure_client do |config|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jt-rails-toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.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-
|
11
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv-rails
|
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: http_accept_language
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: exception_notification
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +66,20 @@ dependencies:
|
|
38
66
|
- - ~>
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '4.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: airbrake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: paperclip
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|