Skip to content

Commit

Permalink
Fix rubocop.yml loading on CI (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbajur authored Nov 28, 2024
1 parent 5651507 commit f9e1b83
Show file tree
Hide file tree
Showing 52 changed files with 233 additions and 279 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ jobs:

- name: Rubocop
run: |
bundle exec rubocop
bundle exec rubocop -c rubocop.yml
58 changes: 5 additions & 53 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,18 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-11-24 19:43:04 UTC using RuboCop version 1.68.0.
# on 2024-11-28 16:46:09 UTC using RuboCop version 1.68.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/OrderedGems:
Exclude:
- 'spec/gemfiles/rails_8.0.gemfile'

# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'inner_performance.gemspec'

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 31

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 29

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 27

# Offense count: 1
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Metrics/ParameterLists:
Max: 7

# Offense count: 13
# Configuration parameters: AllowedConstants.
Style/Documentation:
# Configuration parameters: EnforcedStyle.
# SupportedStyles: def_self, self_class
Style/ClassMethodsDefinitions:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'app/controllers/inner_performance/dashboard_controller.rb'
- 'app/controllers/inner_performance/events_controller.rb'
- 'app/helpers/inner_performance/application_helper.rb'
- 'app/jobs/inner_performance/cleanup_job.rb'
- 'app/jobs/inner_performance/save_event_job.rb'
- 'app/mailers/inner_performance/application_mailer.rb'
- 'app/models/inner_performance/application_record.rb'
- 'app/models/inner_performance/event.rb'
- 'db/migrate/20241123121600_create_inner_performance_events.rb'
- 'db/migrate/20241124111458_add_type_to_inner_performance_events.rb'
- 'lib/inner_performance.rb'
- 'lib/inner_performance/configuration.rb'
- 'lib/inner_performance/engine.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Specify your gem's dependencies in inner_performance.gemspec.
gemspec

eval_gemfile File.expand_path('spec/gemfiles/rails_8.0.gemfile', __dir__)
eval_gemfile File.expand_path("spec/gemfiles/rails_8.0.gemfile", __dir__)
10 changes: 5 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

require 'bundler/setup'
require "bundler/setup"

APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
load 'rails/tasks/engine.rake'
APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
load "rails/tasks/engine.rake"

load 'rails/tasks/statistics.rake'
load "rails/tasks/statistics.rake"

require 'bundler/gem_tasks'
require "bundler/gem_tasks"
10 changes: 5 additions & 5 deletions app/controllers/inner_performance/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def index
@recent_events = InnerPerformance::Event.all.order(id: :desc).limit(25)
@average_req_duration = InnerPerformance::Events::ProcessActionActionController.all.average(:duration)
@average_job_duration = InnerPerformance::Events::PerformActiveJob.average(:duration) || 0
@biggest_events = \
InnerPerformance::Event.select('SUM(duration) as duration, name, COUNT(*) as count, AVG(duration) as avg_duration')
.group(:name)
.order('duration DESC')
.limit(10)
@biggest_events =
InnerPerformance::Event.select("SUM(duration) as duration, name, COUNT(*) as count, AVG(duration) as avg_duration")
.group(:name)
.order("duration DESC")
.limit(10)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/inner_performance/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EventsController < ApplicationController

def index
@q = InnerPerformance::Event.all.ransack(params[:q])
@q.sorts = 'created_at desc' if @q.sorts.empty?
@q.sorts = "created_at desc" if @q.sorts.empty?
@pagy, @events = pagy(@q.result)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/inner_performance/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def row_class_from_duration(duration)
medium_duration_range = InnerPerformance.configuration.medium_duration_range

if duration.between?(medium_duration_range[0], medium_duration_range[1])
'text-warning'
"text-warning"
elsif duration >= medium_duration_range[1]
'text-danger'
"text-danger"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/inner_performance/cleanup_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module InnerPerformance
class CleanupJob < ApplicationJob
def perform
InnerPerformance::Event
.where('created_at < ?', InnerPerformance.configuration.events_retention.ago)
.where("created_at < ?", InnerPerformance.configuration.events_retention.ago)
.destroy_all
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/inner_performance/save_event_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def perform(type:, created_at:, event:, name:, duration:, db_runtime:, propertie
name: name,
duration: duration,
db_runtime: db_runtime,
properties: properties
properties: properties,
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/inner_performance/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module InnerPerformance
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
default from: "from@example.com"
layout "mailer"
end
end
2 changes: 1 addition & 1 deletion app/models/inner_performance/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Event < ApplicationRecord
serialize :properties, coder: JSON

def self.ransackable_attributes(_auth_object = nil)
%w[created_at db_runtime duration event format id name]
["created_at", "db_runtime", "duration", "event", "format", "id", "name"]
end

def self.ransackable_associations(_auth_object = nil)
Expand Down
14 changes: 7 additions & 7 deletions bin/rails
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_ROOT = File.expand_path('..', __dir__)
ENGINE_PATH = File.expand_path('../lib/inner_performance/engine', __dir__)
APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
ENGINE_ROOT = File.expand_path("..", __dir__)
ENGINE_PATH = File.expand_path("../lib/inner_performance/engine", __dir__)
APP_PATH = File.expand_path("../spec/dummy/config/application", __dir__)

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])

require 'rails/all'
require 'rails/engine/commands'
require "rails/all"
require "rails/engine/commands"
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
InnerPerformance::Engine.routes.draw do
resources :events, only: [:index]

root to: 'dashboard#index'
root to: "dashboard#index"
end
16 changes: 8 additions & 8 deletions db/migrate/20241123121600_create_inner_performance_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

class CreateInnerPerformanceEvents < ActiveRecord::Migration[7.1]
def change
create_table :inner_performance_events, force: :cascade do |t|
t.string 'event'
t.string 'name'
t.decimal 'duration'
t.decimal 'db_runtime'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.text 'properties', default: '{}'
create_table(:inner_performance_events, force: :cascade) do |t|
t.string("event")
t.string("name")
t.decimal("duration")
t.decimal("db_runtime")
t.datetime("created_at", null: false)
t.datetime("updated_at", null: false)
t.text("properties", default: "{}")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class AddTypeToInnerPerformanceEvents < ActiveRecord::Migration[7.1]
def change
add_column :inner_performance_events, :type, :string
add_column(:inner_performance_events, :type, :string)
end
end
34 changes: 17 additions & 17 deletions inner_performance.gemspec
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# frozen_string_literal: true

require_relative 'lib/inner_performance/version'
require_relative "lib/inner_performance/version"

Gem::Specification.new do |spec|
spec.name = 'inner_performance'
spec.name = "inner_performance"
spec.version = InnerPerformance::VERSION
spec.authors = ['mbajur']
spec.email = ['mbajur@gmail.com']
spec.homepage = 'https://github.com/mbajur'
spec.summary = 'Database-backed modest performance monitoring tool for your Rails app.'
spec.description = 'Database-backed modest performance monitoring tool for your Rails app.'
spec.authors = ["mbajur"]
spec.email = ["mbajur@gmail.com"]
spec.homepage = "https://github.com/mbajur"
spec.summary = "Database-backed modest performance monitoring tool for your Rails app."
spec.description = "Database-backed modest performance monitoring tool for your Rails app."

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host"
# to allow pushing to a single host or delete this section to allow pushing to any host.

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/mbajur/inner_performance'
spec.metadata['changelog_uri'] = 'https://github.com/mbajur/inner_performance'
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/mbajur/inner_performance"
spec.metadata["changelog_uri"] = "https://github.com/mbajur/inner_performance"

spec.files = Dir.chdir(File.expand_path(__dir__)) do
Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
end

spec.add_dependency 'activejob', '>= 7.1.5'
spec.add_dependency 'pagy', '>= 9.3.1'
spec.add_dependency 'rails', '>= 7.1.5'
spec.add_dependency 'ransack', '>= 4.2.1'
spec.add_dependency("activejob", ">= 7.1.5")
spec.add_dependency("pagy", ">= 9.3.1")
spec.add_dependency("rails", ">= 7.1.5")
spec.add_dependency("ransack", ">= 4.2.1")

spec.add_development_dependency 'factory_bot'
spec.add_development_dependency 'rspec-rails'
spec.add_development_dependency("factory_bot")
spec.add_development_dependency("rspec-rails")
end
20 changes: 10 additions & 10 deletions lib/inner_performance.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require 'inner_performance/version'
require 'inner_performance/engine'
require 'inner_performance/configuration'
require "inner_performance/version"
require "inner_performance/engine"
require "inner_performance/configuration"

require 'ransack'
require 'pagy'
require "ransack"
require "pagy"

module InnerPerformance
class << self
Expand All @@ -18,7 +18,7 @@ def configure
end

def install!
ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |event|
ActiveSupport::Notifications.subscribe("process_action.action_controller") do |event|
if save_event?(event)
InnerPerformance::SaveEventJob.perform_later(
type: InnerPerformance::Events::ProcessActionActionController.name,
Expand All @@ -28,21 +28,21 @@ def install!
duration: event.duration,
db_runtime: event.payload[:db_runtime],
properties: {
view_runtime: event.payload[:view_runtime]
}
view_runtime: event.payload[:view_runtime],
},
)
end
end

ActiveSupport::Notifications.subscribe 'perform.active_job' do |event|
ActiveSupport::Notifications.subscribe("perform.active_job") do |event|
if save_event?(event)
InnerPerformance::SaveEventJob.perform_later(
type: InnerPerformance::Events::PerformActiveJob.name,
created_at: event.payload[:started],
event: event.name,
name: event.payload[:job].class.name,
duration: event.duration,
db_runtime: event.payload[:db_runtime]
db_runtime: event.payload[:db_runtime],
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/inner_performance/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class Configuration

def initialize
@sample_rates = {
'process_action.action_controller' => 2,
'perform.active_job' => 100
"process_action.action_controller" => 2,
"perform.active_job" => 100,
}
@events_retention = 1.week
@medium_duration_range = [200, 999]
@ignore_rules = [
proc { |event| rand(100) > InnerPerformance.configuration.sample_rates[event.name.to_s] },
proc { |event| (event.payload[:job]&.class&.name || '').include?('InnerPerformance') }
proc { |event| (event.payload[:job]&.class&.name || "").include?("InnerPerformance") },
]
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/inner_performance/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ class Engine < ::Rails::Engine
isolate_namespace InnerPerformance

config.generators do |g|
g.test_framework :rspec
g.test_framework(:rspec)
end

initializer 'inner_performance.install' do
initializer "inner_performance.install" do
InnerPerformance.install!
end

initializer 'inner_performance.assets.precompile' do |app|
initializer "inner_performance.assets.precompile" do |app|
# this initializer is only called when sprockets is in use
app.config.assets.precompile << 'inner_performance_manifest.js'
app.config.assets.precompile << "inner_performance_manifest.js"
end
end
end
2 changes: 1 addition & 1 deletion lib/inner_performance/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module InnerPerformance
VERSION = '0.1.4'
VERSION = "0.1.4"
end
2 changes: 2 additions & 0 deletions rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
inherit_from: .rubocop_todo.yml

inherit_gem:
rubocop-shopify: rubocop.yml
Loading

0 comments on commit f9e1b83

Please sign in to comment.