jt-rails-toolbox 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 38a71b9807ecd4b975ac247304de52a4b07131cd
4
+ data.tar.gz: 8fcd255aafa1e5dcb417786881a7932be2d9c551
5
+ SHA512:
6
+ metadata.gz: 42e5dfccb8453f47328d3f42ae34e6ab5474c2d8cac4be92f56a1ca02094cacb19cca45edd89155e2ab9d5d4af62d8b53d7f75457e0b2d9f61e70370198970d1
7
+ data.tar.gz: f6b475a03f55c622549ace0707795b01dbbacaec1e6a172ffe4120492caaee53e956fbd8cd0c7c1e02074bd87b2513c42a43e8d712381b8549f55f4f41d60dda
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ .DS_Store
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Jonathan Tribouharet
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # JTRailsToolboox
2
+
3
+ JTRailsToolboox contains a list of common libs used for rails development.
4
+
5
+ ## Installation
6
+
7
+ JTRailsToolboox is distributed as a gem, which is how it should be used in your app.
8
+
9
+ Include the gem in your Gemfile:
10
+
11
+ gem 'jt-rails-toolboox', '~> 1.0'
12
+
13
+ Create a `jt-toolbox.yml` file:
14
+
15
+ rails g rails_toolbox:install
16
+
17
+ ## What's in it?
18
+
19
+ - [Exception Notification](https://github.com/smartinez87/exception_notification), send email notifications when errors occur
20
+ - [paperclip](https://github.com/thoughtbot/paperclip), manage file upload
21
+ - [quiet_assets](https://github.com/evrone/quiet_assets), silence assets in log
22
+ - [sidekiq](https://github.com/mperham/sidekiq), manage background jobs
23
+ - [validates_email_format_of](https://github.com/validates-email-format-of/validates_email_format_of), who doesn't need to validate email format?
24
+ - simplified configuration of hostnames and `ActionMailer` with YAML
25
+
26
+ ### Exception Notification
27
+
28
+ If `exception` is not set in `jt-toolbox.yml` file, Exception Notification is disabled.
29
+ In addition to the default ignored exceptions, the following exceptions are also muted:
30
+
31
+ - `ActionController::InvalidCrossOriginRequest`
32
+ - `ActionController::InvalidAuthenticityToken`
33
+
34
+ ### Paperclip
35
+
36
+ - `convert_options` is set to `-strip`, which means all metadata of images are removed, this is used for reduced the weight of images.
37
+ - `use_timestamp` is et to `false`, it's a good practice to have unique url for image and url without parameters, instead of using the timestamp we use the fingerprint of the image. [More informations here.](https://github.com/thoughtbot/paperclip#md5-checksum--fingerprint)
38
+ - the default fodler of images is `upload` (in public folder)
39
+
40
+ ### Sidekiq
41
+
42
+ - configured for `ActiveJob`
43
+ - configured to send notification error with Exception Notification
44
+ - redis url is by default `"redis://localhost:6379/#{name of your}"`
45
+
46
+ #### Warning
47
+
48
+ Don't forget to install redis server and to launch sidekiq with
49
+
50
+ `bundle exec sidekiq -q default -q mailers`
51
+
52
+ ### Hostname
53
+
54
+ - `host` is the hostname of your website, it's used for setting the host when you email
55
+ - `asset_host` is the hostname of the assets server. By default equal to `host`.
56
+ - `cdn_host` is the hostname for serving uploaded files with paperclip. By default equal to `asset_host`.
57
+
58
+ It's a good practice to have a different domains for your web server and your file server (search "Cookieless Domain" on google for more informations).
59
+
60
+ ### ActionMailer
61
+
62
+ ActionMailer can be configured easily just with `jt-toolbox.yml` file.
63
+
64
+ ## Author
65
+
66
+ - [Jonathan Tribouharet](https://github.com/jonathantribouharet) ([@johntribouharet](https://twitter.com/johntribouharet))
67
+
68
+ ## License
69
+
70
+ JTRailsToolboox is released under the MIT license. See the LICENSE file for more info.
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'jt-rails-toolbox'
3
+ s.summary = "Common libs used for rails development."
4
+ s.description = "JTRailsToolboox contains a list of common libs used for rails development."
5
+ s.homepage = 'https://github.com/jonathantribouharet/jt-rails-toolbox'
6
+ s.version = '1.0.0'
7
+ s.files = `git ls-files`.split("\n")
8
+ s.require_paths = ['lib']
9
+ s.authors = ['Jonathan TRIBOUHARET']
10
+ s.email = 'jonathan@siu-soon.com'
11
+ s.license = 'MIT'
12
+ s.platform = Gem::Platform::RUBY
13
+
14
+ s.add_dependency('exception_notification', '~> 4.1')
15
+ s.add_dependency('paperclip', '~> 4.2')
16
+ s.add_dependency('quiet_assets', '~> 1.1')
17
+ s.add_dependency('sidekiq', '~> 3.3')
18
+ s.add_dependency('validates_email_format_of', '~> 1.6')
19
+ end
@@ -0,0 +1,3 @@
1
+ Create a default configuration to your Rails App.
2
+
3
+ rails g rails_toolbox:install
@@ -0,0 +1,11 @@
1
+ module RailsToolbox
2
+
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ def create_initializer_file
7
+ copy_file "jt-toolbox.yml", "config/jt-toolbox.yml"
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,37 @@
1
+ # default:
2
+ # files:
3
+ # folder: upload
4
+ # mail:
5
+ # delivery_method: test
6
+ # hosts:
7
+ # host: localhost
8
+ # asset_host: same as host
9
+ # cdn_host: same as host
10
+ # sidekiq:
11
+ # redis_url: redis://localhost:6379/nameoftheapp
12
+
13
+ production:
14
+ exception:
15
+ email_prefix: '[ERROR]'
16
+ sender_address: "Your website <error@example.com>"
17
+ exception_recipients:
18
+ - my_email_for_errors@example.com
19
+ files:
20
+ folder: upload
21
+ mail:
22
+ from: "Your website <contact@example.com>"
23
+ delivery_method: smtp
24
+ smtp_settings:
25
+ address: smtp.gmail.com
26
+ port: 587
27
+ domain: example.com
28
+ user_name: username
29
+ password: password
30
+ authentication: plain
31
+ enable_starttls_auto: true
32
+ hosts:
33
+ host: https://www.example.com
34
+ asset_host: https://asset.example.com
35
+ cdn_host: https://cdn.example.com
36
+ sidekiq:
37
+ redis_url: redis://localhost:6379/my_app
@@ -0,0 +1,120 @@
1
+ require 'exception_notification'
2
+ require 'paperclip'
3
+ require 'sidekiq'
4
+ require 'validates_email_format_of'
5
+
6
+ require 'exception_notification/rails'
7
+ require 'exception_notification/sidekiq'
8
+
9
+ require 'yaml'
10
+
11
+ module JTRailsToolbox
12
+
13
+ class Railtie < ::Rails::Railtie
14
+
15
+ initializer "jt-rails-toolbox" do |app|
16
+ if ::File.exists?('config/jt-toolbox.yml')
17
+ load_params(app)
18
+
19
+ if Rails.env.development?
20
+ require 'quiet_assets'
21
+ end
22
+
23
+ configure_exception_notification(app)
24
+ configure_mail(app)
25
+ configure_paperclip(app)
26
+ configure_sidekiq(app)
27
+ end
28
+ end
29
+
30
+ def load_params(app)
31
+ @params = YAML.load_file('config/jt-toolbox.yml')[Rails.env.to_s] || {}
32
+
33
+ process_params
34
+ end
35
+
36
+ def process_params
37
+ @params['files'] ||= {}
38
+ if @params['files']['folder'].nil?
39
+ @params['files']['folder'] = '/upload'
40
+ else
41
+ # Remove end slash
42
+ @params['files']['folder'].sub!(/\/$/, '')
43
+
44
+ if !@params['files']['folder'].start_with?('/')
45
+ @params['files']['folder'] = "/#{@params['files']['folder']}"
46
+ end
47
+ end
48
+
49
+ @params['mail'] ||= {}
50
+ @params['mail']['delivery_method'] ||= :test
51
+
52
+ @params['mail']['delivery_method'] = @params['mail']['delivery_method'].to_sym
53
+
54
+ @params['mail']['smtp_settings'] ||= {}
55
+ settings = @params['mail']['smtp_settings'].dup
56
+ for key, value in settings
57
+ @params['mail']['smtp_settings'][key.to_sym] = value
58
+ end
59
+
60
+ @params['hosts'] ||= {}
61
+ @params['hosts']['host'] ||= 'http://localhost'
62
+ @params['hosts']['asset_host'] ||= @params['hosts']['host']
63
+ @params['hosts']['cdn_host'] ||= @params['hosts']['asset_host']
64
+
65
+ @params['sidekiq'] ||= {}
66
+ @params['sidekiq']['redis_url'] ||= "redis://localhost:6379/#{Rails.application.class.parent_name.parameterize}"
67
+ end
68
+
69
+ def configure_exception_notification(app)
70
+ return if @params['exception'].nil?
71
+
72
+ ExceptionNotification.configure do |config|
73
+ config.ignored_exceptions += ['ActionController::InvalidCrossOriginRequest', 'ActionController::InvalidAuthenticityToken']
74
+
75
+ config.add_notifier :email, {
76
+ email_prefix: @params['exception']['email_prefix'],
77
+ sender_address: @params['exception']['sender_address'],
78
+ exception_recipients: @params['exception']['exception_recipients']
79
+ }
80
+ end
81
+ end
82
+
83
+ def configure_mail(app)
84
+ ActionMailer::Base.delivery_method = @params['mail']['delivery_method']
85
+ ActionMailer::Base.smtp_settings = @params['mail']['smtp_settings']
86
+ ActionMailer::Base.default_url_options[:host] = @params['hosts']['host']
87
+ ActionMailer::Base.default from: @params['mail']['from']
88
+ end
89
+
90
+ def configure_paperclip(app)
91
+ # Strip meta data from images
92
+ Paperclip::Attachment.default_options[:convert_options] = { all: '-strip' }
93
+
94
+ # Params in url are bad for SEO, it's better to use fingerprint for having a unique url
95
+ Paperclip::Attachment.default_options[:use_timestamp] = false
96
+
97
+ path = "#{@params['files']['folder']}/:class/:attachment/:id/:style/:fingerprint.:content_type_extension"
98
+
99
+ Paperclip::Attachment.default_options[:path] = ":rails_root/public/#{path}"
100
+ Paperclip::Attachment.default_options[:url] = "#{@params['hosts']['cdn_host']}#{path}"
101
+ app.config.action_controller.asset_host = @params['hosts']['asset_host']
102
+ end
103
+
104
+ def configure_sidekiq(app)
105
+ Sidekiq.configure_server do |config|
106
+ config.redis = { url: @params['sidekiq']['redis_url'] }
107
+
108
+ config.error_handlers << Proc.new {|ex, ctx_hash| ExceptionNotifier.notify_exception(ex, data: ctx_hash) }
109
+ end
110
+
111
+ Sidekiq.configure_client do |config|
112
+ config.redis = { url: @params['sidekiq']['redis_url'] }
113
+ end
114
+
115
+ ActiveJob::Base.queue_adapter = :sidekiq
116
+ end
117
+
118
+ end
119
+
120
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jt-rails-toolbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan TRIBOUHARET
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: exception_notification
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: paperclip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: quiet_assets
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sidekiq
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: validates_email_format_of
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ description: JTRailsToolboox contains a list of common libs used for rails development.
84
+ email: jonathan@siu-soon.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - LICENSE
91
+ - README.md
92
+ - jt-rails-toolbox.gemspec
93
+ - lib/generators/rails_toolbox/USAGE
94
+ - lib/generators/rails_toolbox/install_generator.rb
95
+ - lib/generators/rails_toolbox/templates/jt-toolbox.yml
96
+ - lib/jt-rails-toolbox.rb
97
+ homepage: https://github.com/jonathantribouharet/jt-rails-toolbox
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.0.14
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Common libs used for rails development.
121
+ test_files: []