permadeps 1446.1.3 → 1446.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc250bd5ba2e7653b5389a8591edc0d95026994276bab7d6f8819ada1b2a0be6
4
- data.tar.gz: 750e7413ecfaf6a750be7c5862d966dace6b8b3618fa6ccd23764a1acb926eaa
3
+ metadata.gz: b03699be940d87364b352bc06bad1e4fa1e05fc1117ee7d53df8a707b5751281
4
+ data.tar.gz: ad0bf6ac5dbfb8eb6a119aa453c97b833f7e7e7ea2ea48605c42b07447129506
5
5
  SHA512:
6
- metadata.gz: b82feaa7df1a7d26220548f2ed1c92a46cefec39d155f52a9e00172ad7905d70ec02b811c65c98549599a2f4036592188f82448a167314402734a1dcee5d9dfb
7
- data.tar.gz: aec0aa392c88b1f31b3f68370a3d807d685818afb4b15792f5665faa56ce371bd61edfb877c44fc6fd3881af2f3237d4bedb9c4af2814d60f5c1c4141d1e3c59
6
+ metadata.gz: 9ff649e19d3f73ad7d96e27413b6052487f48bbc753f6a4224feaee09641aeee1915060e1c099939be49bdecdfa7921720f60a8365b72c7005c40badcf0c0736
7
+ data.tar.gz: 557cc71fbcc1bc402e0340a8da6f177bc8815fbd6a3bc59a18c781c096c8a9c7a44be95639c9d20b328196ae373bf19ab04e528567710163cc55db5bcf797384
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # permadeps
2
2
 
3
- Ruby gem holds my permanent dependencies and configs I'm using in my Rails projects.
3
+ Ruby gem that holds permanent dependencies and configurations for Rails projects.
4
4
 
5
- This gem is compatible with [this](https://github.com/AliOsm/ruby-on-rails-devcontainer) DevContainer setup.
5
+ This gem is compatible with [this Ruby on Rails DevContainer setup](https://github.com/AliOsm/ruby-on-rails-devcontainer).
6
6
 
7
7
  ## Installation
8
8
 
9
- Install the gem and add it to the Rails application's Gemfile by executing:
9
+ Add the gem to your Rails application's Gemfile by executing:
10
10
 
11
11
  ```bash
12
12
  $ bundle add permadeps
@@ -14,45 +14,49 @@ $ bundle add permadeps
14
14
 
15
15
  ## Usage
16
16
 
17
- Adding this gem to your Rails project will provide you with the following gems:
18
-
19
- ### Production dependencies:
20
- - [`ahoy_matey`](https://github.com/ankane/ahoy) (Will be required)
21
- - [`better_html`](https://github.com/Shopify/better-html) (Will be required)
22
- - [`blazer`](https://github.com/ankane/blazer) (Will be required)
23
- - [`flamegraph`](https://github.com/SamSaffron/flamegraph) (Will be required)
24
- - [`freezolite`](https://github.com/ruby-next/freezolite)
25
- - [`geocoder`](https://github.com/alexreisner/geocoder)
26
- - [`memory_profiler`](https://github.com/SamSaffron/memory_profiler) (Will be required)
27
- - [`notable`](https://github.com/ankane/notable) (Will be required)
28
- - [`pghero`](https://github.com/ankane/pghero) (Will be required)
29
- - [`pg_query`](https://github.com/pganalyze/pg_query)
30
- - [`rack-mini-profiler`](https://github.com/MiniProfiler/rack-mini-profiler) (Will be required)
31
- - [`stackprof`](https://github.com/tmm1/stackprof) (Will be required)
32
-
33
- ### Development dependencies:
34
- - [`annotaterb`](https://github.com/drwl/annotaterb)
35
- - [`better_errors`](https://github.com/BetterErrors/better_errors)
36
- - [`binding_of_caller`](https://github.com/banister/binding_of_caller)
37
- - [`brakeman`](https://github.com/presidentbeef/brakeman)
38
- - [`bullet`](https://github.com/flyerhzm/bullet) (Will be required in development environment only)
39
- - [`bundler-audit`](https://github.com/rubysec/bundler-audit)
40
- - [`dotenv`](https://github.com/bkeepers/dotenv)
41
- - [`erb-formatter`](https://github.com/nebulab/erb-formatter)
42
- - [`erb_lint`](https://github.com/Shopify/erb-lint)
43
- - [`i18n-tasks`](https://github.com/glebm/i18n-tasks)
44
- - [`rubocop`](https://github.com/rubocop/rubocop)
45
- - [`rubocop-minitest`](https://github.com/rubocop/rubocop-minitest)
46
- - [`rubocop-performance`](https://github.com/rubocop/rubocop-performance)
47
- - [`rubocop-rails`](https://github.com/rubocop/rubocop-rails)
48
- - [`rubocop-rake`](https://github.com/rubocop/rubocop-rake)
49
- - [`rubocop-rspec`](https://github.com/rubocop/rubocop-rspec)
50
- - [`rubocop-rspec_rails`](https://github.com/rubocop/rubocop-rspec_rails)
51
- - [`ruby_audit`](https://github.com/civisanalytics/ruby_audit)
52
-
53
- #### Rubocop
54
-
55
- For `rubocop` gem, use the following configuration file to inherit from `permadeps` gem:
17
+ Adding this gem to your Rails project provides you with the following gems and features:
18
+
19
+ ### Production Dependencies
20
+
21
+ The following gems will be automatically required:
22
+
23
+ - [`ahoy_matey`](https://github.com/ankane/ahoy): Analytics for Rails
24
+ - [`better_html`](https://github.com/Shopify/better-html): Better HTML for Rails
25
+ - [`blazer`](https://github.com/ankane/blazer): Business intelligence made simple
26
+ - [`flamegraph`](https://github.com/SamSaffron/flamegraph): Flamegraph profiler
27
+ - [`geocoder`](https://github.com/alexreisner/geocoder): Geocoding solution
28
+ - [`good_job`](https://github.com/bensheldon/good_job): Multithreaded, Postgres-based, Active Job backend
29
+ - [`memory_profiler`](https://github.com/SamSaffron/memory_profiler): Memory profiling tool
30
+ - [`notable`](https://github.com/ankane/notable): Automatic tracking for requests and background jobs
31
+ - [`pghero`](https://github.com/ankane/pghero): PostgreSQL insights
32
+ - [`rack-mini-profiler`](https://github.com/MiniProfiler/rack-mini-profiler): Profiler for Rack applications
33
+ - [`rails_performance`](https://github.com/igorkasyanchuk/rails_performance): Self-hosted performance monitoring
34
+ - [`stackprof`](https://github.com/tmm1/stackprof): Sampling call-stack profiler
35
+
36
+ Additional production dependencies (not automatically required):
37
+
38
+ - [`freezolite`](https://github.com/ruby-next/freezolite): Automatic string freezing
39
+ - [`pg_query`](https://github.com/pganalyze/pg_query): PostgreSQL query parsing
40
+
41
+ ### Development Dependencies
42
+
43
+ - [`annotaterb`](https://github.com/drwl/annotaterb): Annotate Rails models
44
+ - [`better_errors`](https://github.com/BetterErrors/better_errors): Better error page for Rails
45
+ - [`binding_of_caller`](https://github.com/banister/binding_of_caller): Retrieve the binding of a method's caller
46
+ - [`brakeman`](https://github.com/presidentbeef/brakeman): Security vulnerability scanner
47
+ - [`bullet`](https://github.com/flyerhzm/bullet): Help to kill N+1 queries (automatically required in development)
48
+ - [`bundler-audit`](https://github.com/rubysec/bundler-audit): Patch-level verification for Bundler
49
+ - [`dotenv`](https://github.com/bkeepers/dotenv): Load environment variables from `.env`
50
+ - [`erb-formatter`](https://github.com/nebulab/erb-formatter): ERB formatter
51
+ - [`erb_lint`](https://github.com/Shopify/erb-lint): ERB linter
52
+ - [`i18n-tasks`](https://github.com/glebm/i18n-tasks): Manage translation and localization
53
+ - [`rubocop`](https://github.com/rubocop/rubocop) and related gems: Ruby static code analyzer and formatter
54
+
55
+ ## Configuration
56
+
57
+ ### Rubocop
58
+
59
+ To use the `rubocop` configuration provided by `permadeps`, add the following to your `.rubocop.yml`:
56
60
 
57
61
  ```yml
58
62
  inherit_gem:
@@ -60,22 +64,61 @@ inherit_gem:
60
64
  - rubocop.yml
61
65
  ```
62
66
 
63
- #### Formatters
67
+ ### Formatters
64
68
 
65
- `erb-formatter` and `erb_lint` requires the following VSCode extensions to work properly:
69
+ For `erb-formatter` and `erb_lint` to work properly in VSCode, install these extensions:
66
70
  - [Ruby ERB::Formatter](https://marketplace.visualstudio.com/items?itemName=elia.erb-formatter)
67
71
  - [ERB Linter](https://marketplace.visualstudio.com/items?itemName=manuelpuyol.erb-linter)
68
72
 
69
- Make sure to setup the other gems properly in your Rails application.
70
-
71
- ### Generator
73
+ ## Generator
72
74
 
73
- The gem also provides a generator to install the necessary files to the Rails application:
75
+ The gem provides a generator to install necessary files and configurations:
74
76
 
75
77
  ```bash
76
78
  $ rails g permadeps:install
77
79
  ```
78
80
 
81
+ This generator will perform the following actions:
82
+
83
+ 1. Copy configuration files:
84
+ - `.annotaterb.yml`: Configuration for AnnotateRb
85
+ - `.better-html.yml`: Configuration for Better HTML
86
+ - `.env.example`: Example environment variables file
87
+ - `.erb-lint.yml`: Configuration for ERB Lint
88
+ - `.rubocop.yml`: Configuration for RuboCop
89
+
90
+ 2. Copy initializers:
91
+ - `config/initializers/better_html.rb`: Sets up Better HTML
92
+ - `config/initializers/blazer.rb`: Configures Blazer
93
+ - `config/initializers/rack_mini_profiler.rb`: Sets up Rack Mini Profiler
94
+ - `config/initializers/rails_performance.rb`: Sets up Rails Performance
95
+
96
+ 3. Add background jobs for PgHero:
97
+ - `app/jobs/capture_query_stats_job.rb`: Captures query statistics
98
+ - `app/jobs/capture_space_stats_job.rb`: Captures space usage statistics
99
+ - `app/jobs/clean_query_stats_job.rb`: Cleans up old query statistics
100
+ - `app/jobs/clean_space_stats_job.rb`: Cleans up old space usage statistics
101
+
102
+ 4. Add a rake task:
103
+ - `lib/tasks/annotate_rb.rake`: Task for running Annotate
104
+
105
+ 5. Run generators for various gems:
106
+ - `ahoy:install`: Sets up Ahoy for analytics
107
+ - `blazer:install`: Installs Blazer for business intelligence
108
+ - `good_job:install`: Sets up GoodJob
109
+ - `notable:requests`: Sets up Notable for request tracking
110
+ - `notable:jobs`: Sets up Notable for job tracking
111
+ - `pghero:query_stats`: Installs PgHero query stats
112
+ - `pghero:space_stats`: Installs PgHero space stats
113
+
114
+ 6. Set up Freezolite:
115
+ - Adds `require 'freezolite/auto'` to `config/application.rb` for automatic string freezing
116
+
117
+ 7. Run database migrations:
118
+ - Executes `rails db:migrate` to apply all pending migrations
119
+
120
+ After running the generator, your Rails application will be configured with all the necessary settings and files to use the gems provided by permadeps. Make sure to review the generated files and adjust them as needed for your specific project requirements.
121
+
79
122
  ## License
80
123
 
81
124
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -15,6 +15,7 @@ module Permadeps
15
15
  copy_file 'initializers/better_html.rb', 'config/initializers/better_html.rb'
16
16
  copy_file 'initializers/blazer.rb', 'config/initializers/blazer.rb'
17
17
  copy_file 'initializers/rack_mini_profiler.rb', 'config/initializers/rack_mini_profiler.rb'
18
+ copy_file 'initializers/rails_performance.rb', 'config/initializers/rails_performance.rb'
18
19
  end
19
20
 
20
21
  def copy_jobs
@@ -31,14 +32,73 @@ module Permadeps
31
32
  def run_generators
32
33
  generate 'ahoy:install'
33
34
  generate 'blazer:install'
35
+ generate 'good_job:install'
34
36
  generate 'notable:requests'
35
37
  generate 'notable:jobs'
36
38
  generate 'pghero:query_stats'
37
39
  generate 'pghero:space_stats'
38
40
  end
39
41
 
42
+ def setup_good_job # rubocop:disable Metrics/MethodLength
43
+ append_to_file 'Procfile.dev', "worker: bundle exec good_job start\n"
44
+
45
+ gsub_file(
46
+ 'config/environments/production.rb',
47
+ '# config.active_job.queue_adapter = :resque',
48
+ 'config.active_job.queue_adapter = :good_job'
49
+ )
50
+
51
+ insert_into_file 'config/environments/production.rb', before: /^end/ do
52
+ <<-RUBY
53
+
54
+ config.good_job.enable_cron = true
55
+
56
+ config.good_job.cron = {
57
+ capture_space_stats: {
58
+ cron: '*/5 * * * *',
59
+ class: 'CaptureSpaceStatsJob',
60
+ description: 'Capture PgHero space statistics every 5 minutes'
61
+ },
62
+ clean_space_stats: {
63
+ cron: '0 0 * * 5',
64
+ class: 'CleanSpaceStatsJob',
65
+ description: 'Clean PgHero space statistics every Friday midnight'
66
+ },
67
+ capture_query_stats: {
68
+ cron: '*/5 * * * *',
69
+ class: 'CaptureQueryStatsJob',
70
+ description: 'Capture PgHero query statistics every 5 minutes'
71
+ },
72
+ clean_query_stats: {
73
+ cron: '0 0 * * 5',
74
+ class: 'CleanQueryStatsJob',
75
+ description: 'Clean PgHero query statistics every Friday midnight'
76
+ }
77
+ }
78
+ RUBY
79
+ end
80
+ end
81
+
40
82
  def setup_freezolite_gem
41
- insert_into_file 'config/application.rb', "\n\nrequire 'freezolite/auto'", after: "Bundler.require(*Rails.groups)"
83
+ insert_into_file(
84
+ 'config/application.rb',
85
+ "\n\nrequire 'freezolite/auto'",
86
+ after: 'Bundler.require(*Rails.groups)'
87
+ )
88
+ end
89
+
90
+ def insert_engines
91
+ insert_into_file 'config/routes.rb', before: /^end/ do
92
+ <<-RUBY
93
+
94
+ authenticate :user, ->(user) { user.admin? } do
95
+ mount Blazer::Engine, at: 'rails/blazer'
96
+ mount GoodJob::Engine, at: 'rails/good_job'
97
+ mount PgHero::Engine, at: 'rails/pghero'
98
+ mount RailsPerformance::Engine, at: 'rails/performance'
99
+ end
100
+ RUBY
101
+ end
42
102
  end
43
103
 
44
104
  def run_migrations
@@ -0,0 +1,42 @@
1
+ if defined?(RailsPerformance)
2
+ Rails.autoloaders.main.on_load('RailsPerformance::RailsPerformanceController') do
3
+ RailsPerformance::RailsPerformanceController.content_security_policy false
4
+ end
5
+
6
+ RailsPerformance.setup do |config|
7
+ config.redis = Redis::Namespace.new("#{Rails.env}-rails-performance",
8
+ redis: Redis.new(url: ENV.fetch('REDIS_URL', 'redis://redis:6379')))
9
+ config.duration = 24.hours
10
+
11
+ config.debug = false # currently not used>
12
+ config.enabled = true
13
+
14
+ # default path where to mount gem
15
+ config.mount_at = '/rails/performance'
16
+
17
+ # protect your Performance Dashboard with HTTP BASIC password
18
+ config.http_basic_authentication_enabled = false
19
+ config.http_basic_authentication_user_name = 'rails_performance'
20
+ config.http_basic_authentication_password = 'password12'
21
+
22
+ # if you need an additional rules to check user permissions
23
+ config.verify_access_proc = proc { |_controller| true }
24
+ # for example when you have `current_user`
25
+ # config.verify_access_proc = proc { |controller| controller.current_user && controller.current_user.admin? }
26
+
27
+ # You can ignore endpoints with Rails standard notation controller#action
28
+ # config.ignored_endpoints = ['HomeController#contact']
29
+
30
+ # store custom data for the request
31
+ # config.custom_data_proc = proc do |env|
32
+ # request = Rack::Request.new(env)
33
+ # {
34
+ # email: request.env['warden'].user&.email, # if you are using Devise for example
35
+ # user_agent: request.env['HTTP_USER_AGENT']
36
+ # }
37
+ # end
38
+
39
+ # config home button link
40
+ config.home_link = '/'
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Permadeps
2
- VERSION = '1446.1.3'
2
+ VERSION = '1446.1.4'
3
3
  end
data/lib/permadeps.rb CHANGED
@@ -3,10 +3,12 @@ require 'blazer'
3
3
  require 'better_html'
4
4
  require 'flamegraph'
5
5
  require 'geocoder'
6
+ require 'good_job'
6
7
  require 'memory_profiler'
7
8
  require 'notable'
8
9
  require 'pghero'
9
10
  require 'rack-mini-profiler'
11
+ require 'rails_performance'
10
12
  require 'stackprof'
11
13
 
12
14
  require 'bullet' if defined?(Rails) && Rails.env.development?
data/permadeps.gemspec CHANGED
@@ -39,11 +39,13 @@ Gem::Specification.new do |spec|
39
39
  spec.add_dependency 'flamegraph', '~> 0.9.5'
40
40
  spec.add_dependency 'freezolite', '~> 0.5.0'
41
41
  spec.add_dependency 'geocoder', '~> 1.8', '>= 1.8.3'
42
+ spec.add_dependency 'good_job', '~> 4.1'
42
43
  spec.add_dependency 'memory_profiler', '~> 1.0', '>= 1.0.2'
43
44
  spec.add_dependency 'notable', '~> 0.5.2'
44
45
  spec.add_dependency 'pghero', '~> 3.6'
45
46
  spec.add_dependency 'pg_query', '~> 5.1'
46
47
  spec.add_dependency 'rack-mini-profiler', '~> 3.3', '>= 3.3.1'
48
+ spec.add_dependency 'rails_performance', '~> 1.2', '>= 1.2.2'
47
49
  spec.add_dependency 'stackprof', '~> 0.2.26'
48
50
 
49
51
  # Development dependencies:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: permadeps
3
3
  version: !ruby/object:Gem::Version
4
- version: 1446.1.3
4
+ version: 1446.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Hamdi Ali Fadel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-27 00:00:00.000000000 Z
11
+ date: 2024-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ahoy_matey
@@ -112,6 +112,20 @@ dependencies:
112
112
  - - ">="
113
113
  - !ruby/object:Gem::Version
114
114
  version: 1.8.3
115
+ - !ruby/object:Gem::Dependency
116
+ name: good_job
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '4.1'
122
+ type: :runtime
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '4.1'
115
129
  - !ruby/object:Gem::Dependency
116
130
  name: memory_profiler
117
131
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +208,26 @@ dependencies:
194
208
  - - ">="
195
209
  - !ruby/object:Gem::Version
196
210
  version: 3.3.1
211
+ - !ruby/object:Gem::Dependency
212
+ name: rails_performance
213
+ requirement: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - "~>"
216
+ - !ruby/object:Gem::Version
217
+ version: '1.2'
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: 1.2.2
221
+ type: :runtime
222
+ prerelease: false
223
+ version_requirements: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - "~>"
226
+ - !ruby/object:Gem::Version
227
+ version: '1.2'
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: 1.2.2
197
231
  - !ruby/object:Gem::Dependency
198
232
  name: stackprof
199
233
  requirement: !ruby/object:Gem::Requirement
@@ -543,6 +577,7 @@ files:
543
577
  - lib/generators/permadeps/install/templates/initializers/better_html.rb
544
578
  - lib/generators/permadeps/install/templates/initializers/blazer.rb
545
579
  - lib/generators/permadeps/install/templates/initializers/rack_mini_profiler.rb
580
+ - lib/generators/permadeps/install/templates/initializers/rails_performance.rb
546
581
  - lib/generators/permadeps/install/templates/jobs/capture_query_stats_job.rb
547
582
  - lib/generators/permadeps/install/templates/jobs/capture_space_stats_job.rb
548
583
  - lib/generators/permadeps/install/templates/jobs/clean_query_stats_job.rb