peak_flow_utils 0.1.8 → 0.1.13

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +30 -5
  3. data/app/controllers/peak_flow_utils/application_controller.rb +6 -1
  4. data/app/controllers/peak_flow_utils/pings/postgres_connections_controller.rb +10 -0
  5. data/app/controllers/peak_flow_utils/pings/sidekiq_controller.rb +13 -0
  6. data/app/handlers/peak_flow_utils/validations_handler.rb +3 -3
  7. data/app/{migrations → services}/peak_flow_utils/application_migration.rb +0 -0
  8. data/app/services/peak_flow_utils/database_initializer_service.rb +3 -3
  9. data/app/services/peak_flow_utils/erb_inspector/file_inspector.rb +4 -4
  10. data/app/services/peak_flow_utils/erb_inspector/translation_inspector.rb +7 -7
  11. data/app/services/peak_flow_utils/handlers_finder_service.rb +2 -2
  12. data/app/services/peak_flow_utils/model_inspector.rb +1 -0
  13. data/app/services/peak_flow_utils/translations_parser_service.rb +3 -3
  14. data/bin/peak_flow_rspec_files +1 -1
  15. data/config/routes.rb +4 -0
  16. data/lib/peak_flow_utils.rb +16 -1
  17. data/{app → lib/peak_flow_utils}/migrations/20150902155200_create_translation_keys.rb +0 -0
  18. data/{app/migrations/20150907090900_create_handlers.rb → lib/peak_flow_utils/migrations/20150907070908_create_handlers.rb} +0 -0
  19. data/{app → lib/peak_flow_utils}/migrations/20150907070909_create_groups.rb +0 -0
  20. data/{app → lib/peak_flow_utils}/migrations/20150908085500_create_translation_values.rb +0 -0
  21. data/{app → lib/peak_flow_utils}/migrations/20150908090800_create_handler_texts.rb +0 -0
  22. data/{app → lib/peak_flow_utils}/migrations/20160411190500_create_scanned_files.rb +0 -0
  23. data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/application_record.rb +0 -0
  24. data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/group.rb +0 -0
  25. data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/handler.rb +0 -0
  26. data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/handler_text.rb +0 -0
  27. data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/scanned_file.rb +0 -0
  28. data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/translation_key.rb +0 -0
  29. data/{app/models/peak_flow_utils → lib/peak_flow_utils/models}/translation_value.rb +0 -0
  30. data/lib/peak_flow_utils/notifier.rb +83 -0
  31. data/lib/peak_flow_utils/notifier_error_parser.rb +53 -0
  32. data/lib/peak_flow_utils/notifier_rack.rb +22 -0
  33. data/lib/peak_flow_utils/notifier_rails.rb +5 -0
  34. data/lib/peak_flow_utils/notifier_response.rb +11 -0
  35. data/lib/peak_flow_utils/notifier_sidekiq.rb +11 -0
  36. data/lib/peak_flow_utils/rspec_helper.rb +31 -17
  37. data/lib/peak_flow_utils/version.rb +1 -1
  38. metadata +27 -41
  39. data/app/assets/config/peak_flow_utils_manifest.js +0 -2
  40. data/app/assets/javascripts/peak_flow_utils/application.js +0 -14
  41. data/app/assets/stylesheets/peak_flow_utils/application.css +0 -15
  42. data/app/controllers/peak_flow_utils/pings/sidekiq_pings_controller.rb +0 -10
  43. data/app/helpers/peak_flow_utils/application_helper.rb +0 -2
  44. data/app/jobs/peak_flow_utils/application_job.rb +0 -2
  45. data/app/mailers/peak_flow_utils/application_mailer.rb +0 -4
  46. data/app/views/layouts/peak_flow_utils/application.html.erb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ad82e3f289b2fec7d3ede11c831b39c263e7f39a55a7ffa57c9d27352bd1fac
4
- data.tar.gz: 5957b886c48dc56d0b8a0fe2710ef075a715ad06310c1f177fdf36246a50f93d
3
+ metadata.gz: b141fd3f60e179e1d4e3f102b99d072a0058c59e86cceb24f64a06e0257606e7
4
+ data.tar.gz: a7b8374c5efb473cd97a122d03e44cb007f5a01ca49b8da0735c533e988de2f4
5
5
  SHA512:
6
- metadata.gz: e99e21d3f08b35ab3b5325b60e918eba8c2b391dc302e7b66fd8607c794c940ea58404eb1ef1c6e41eff02c760ad92df46ab1084e57ee0d4193ebdd228a42062
7
- data.tar.gz: c92a8a0455968d4f136cf17bb6e5eddfeb5f4fc7a669cbb1ef5c7543cbd589e0d0911120e6e909ffe61c9a7a9ed214b931ae048dd622522e0944aa94d28663c0
6
+ metadata.gz: ee4466d32017db9534d5d5f037f077e559442b9cf104b0eef9e814f3e8c0f6579245024f38a026060ead15ba5c1f629e1329e67426e194c93becf0207bfef2c7
7
+ data.tar.gz: 2623cd9f15885a9585ca2d47b6af5940eb44f210d1d55a3c1a93c62262fd8624e21c6d91e8c894fd107758f06e5aab0be2a2bd11d009e1b0d12314439e64adf6
data/README.md CHANGED
@@ -1,14 +1,12 @@
1
- # PeakFlowUtils
2
- Short description and motivation.
1
+ # PeakflowUtils
3
2
 
4
- ## Usage
5
- How to use my plugin.
3
+ Various tools to use with www.peakflow.io.
6
4
 
7
5
  ## Installation
8
6
  Add this line to your application's Gemfile:
9
7
 
10
8
  ```ruby
11
- gem 'peak_flow_utils'
9
+ gem "peak_flow_utils"
12
10
  ```
13
11
 
14
12
  And then execute:
@@ -21,6 +19,33 @@ Or install it yourself as:
21
19
  $ gem install peak_flow_utils
22
20
  ```
23
21
 
22
+ Add this to `config/peakflow.rb`:
23
+ ```ruby
24
+ PeakFlowUtils::Notifier.configure(auth_token: "your-token")
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Reporting errors manually
30
+
31
+ ```ruby
32
+ PeakFlowUtils::Notifier.notify(error: error)
33
+ ```
34
+
35
+ ### Reporting Rails errors
36
+
37
+ Add this to `config/peakflow.rb`:
38
+ ```ruby
39
+ PeakFlowUtils::NotifierRails.configure
40
+ ```
41
+
42
+ ### Reporting Sidekiq errors in Rails:
43
+
44
+ Add this to `config/peakflow.rb`:
45
+ ```ruby
46
+ PeakFlowUtils::NotifierSidekiq.configure
47
+ ```
48
+
24
49
  ## Contributing
25
50
  Contribution directions go here.
26
51
 
@@ -7,7 +7,12 @@ private
7
7
 
8
8
  def authenticate
9
9
  authenticate_or_request_with_http_basic do |username, password|
10
- username == ENV.fetch("PEAK_FLOW_PINGS_USERNAME") && password == ENV.fetch("PEAK_FLOW_PINGS_PASSWORD")
10
+ if ENV["PEAKFLOW_PINGS_USERNAME"].blank? || ENV["PEAKFLOW_PINGS_PASSWORD"].blank?
11
+ Rails.logger.error "Peakflow utils: Pings called but PEAKFLOW_PINGS_USERNAME or PEAKFLOW_PINGS_PASSWORD wasn't set"
12
+ false
13
+ end
14
+
15
+ username == ENV.fetch("PEAKFLOW_PINGS_USERNAME") && password == ENV.fetch("PEAKFLOW_PINGS_PASSWORD")
11
16
  end
12
17
  end
13
18
  end
@@ -0,0 +1,10 @@
1
+ class PeakFlowUtils::Pings::PostgresConnectionsController < PeakFlowUtils::ApplicationController
2
+ def count
3
+ postgres_connections_count = ActiveRecord::Base.connection.execute("SELECT SUM(numbackends) AS connections_count FROM pg_stat_database").to_a.first
4
+
5
+ render json: {
6
+ check_json_status: "OK",
7
+ postgres_connections_count: postgres_connections_count.fetch("connections_count")
8
+ }
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require "sidekiq/api"
2
+
3
+ class PeakFlowUtils::Pings::SidekiqController < PeakFlowUtils::ApplicationController
4
+ def index
5
+ sidekiq_queue = Sidekiq::Queue.new
6
+
7
+ render json: {
8
+ check_json_status: "OK",
9
+ latency: sidekiq_queue.latency,
10
+ queue_size: sidekiq_queue.size
11
+ }
12
+ end
13
+ end
@@ -23,11 +23,11 @@ class PeakFlowUtils::ValidationsHandler < PeakFlowUtils::ApplicationHandler
23
23
  translations_for_format_validator(validator, model_inspector, attribute_name, yielder)
24
24
  elsif validator.is_a?(ActiveRecord::Validations::UniquenessValidator)
25
25
  translations_for_uniqueness_validator(validator, model_inspector, attribute_name, yielder)
26
- elsif validator.class.name == "ActiveRecord::Validations::PresenceValidator"
26
+ elsif validator.class.name == "ActiveRecord::Validations::PresenceValidator" # rubocop:disable Style/ClassEqualityComparison
27
27
  translations_for_presence_validator(validator, model_inspector, attribute_name, yielder)
28
- elsif validator.class.name == "EmailValidator"
28
+ elsif validator.class.name == "EmailValidator" # rubocop:disable Style/ClassEqualityComparison
29
29
  translations_for_email_validator(validator, model_inspector, attribute_name, yielder)
30
- elsif validator.class.name == "ActiveModel::Validations::ConfirmationValidator"
30
+ elsif validator.class.name == "ActiveModel::Validations::ConfirmationValidator" # rubocop:disable Style/ClassEqualityComparison
31
31
  translations_for_confirmation_validator(validator, model_inspector, attribute_name, yielder)
32
32
  else
33
33
  Rails.logger.error "Unhandeled validator: #{validator.class.name}"
@@ -1,6 +1,6 @@
1
1
  class PeakFlowUtils::DatabaseInitializerService < PeakFlowUtils::ApplicationService
2
- def execute
3
- path = File.realpath("#{File.dirname(__FILE__)}/../../migrations")
2
+ def perform
3
+ path = File.realpath("#{__dir__}/../../../lib/peak_flow_utils/migrations")
4
4
  create_schema_table unless schema_table_exists?
5
5
 
6
6
  Dir["#{path}/[0-9]*_*.rb"].sort.map do |filename|
@@ -22,7 +22,7 @@ class PeakFlowUtils::DatabaseInitializerService < PeakFlowUtils::ApplicationServ
22
22
  private
23
23
 
24
24
  def create_schema_table
25
- PeakFlowUtils::ApplicationRecord.connection.execute("CREATE TABLE schema_migrations (version VARCHAT)")
25
+ PeakFlowUtils::ApplicationRecord.connection.execute("CREATE TABLE schema_migrations (version VARCHAR)")
26
26
  end
27
27
 
28
28
  def register_migration_migrated(version)
@@ -58,19 +58,19 @@ class PeakFlowUtils::ErbInspector::FileInspector
58
58
  private
59
59
 
60
60
  def parse_content_liquid(line_no, line, translations_found, yielder)
61
- line.scan(/\"([^\"]+?)\"\s+\|\s+t\s*(\%}|\}\}|\|)/) do |match|
61
+ line.scan(/"([^"]+?)"\s+\|\s+t\s*(%}|\}\}|\|)/) do |match|
62
62
  add_translation(line_no, "t", match[0], translations_found, yielder)
63
63
  end
64
64
 
65
- line.scan(/\'([^\']+?)\'\s+\|\s+t\s*(\%}|\}\}|\|)/) do |match|
65
+ line.scan(/'([^']+?)'\s+\|\s+t\s*(%}|\}\}|\|)/) do |match|
66
66
  add_translation(line_no, "t", match[0], translations_found, yielder)
67
67
  end
68
68
 
69
- line.scan(/\"([^\"]+?)\"\s+\|\s+val:\s*\"([^\"]+?)\"\s*,\s*(.+?)\s*\|\s+t\s*/) do |match|
69
+ line.scan(/"([^"]+?)"\s+\|\s+val:\s*"([^"]+?)"\s*,\s*(.+?)\s*\|\s+t\s*/) do |match|
70
70
  add_translation(line_no, "t", match[0], translations_found, yielder)
71
71
  end
72
72
 
73
- line.scan(/'([^\"]+?)'\s+\|\s+val:\s*'([^\"]+?)'\s*,\s*(.+?)\s*\|\s+t\s*/) do |match|
73
+ line.scan(/'([^"]+?)'\s+\|\s+val:\s*'([^"]+?)'\s*,\s*(.+?)\s*\|\s+t\s*/) do |match|
74
74
  add_translation(line_no, "t", match[0], translations_found, yielder)
75
75
  end
76
76
  end
@@ -27,7 +27,7 @@ class PeakFlowUtils::ErbInspector::TranslationInspector
27
27
  end
28
28
 
29
29
  def global?
30
- !relative? && !key.include?(".")
30
+ !relative? && key.exclude?(".")
31
31
  end
32
32
 
33
33
  def relative?
@@ -49,16 +49,16 @@ private
49
49
  is_mailer = true
50
50
  elsif @full_key.start_with?("app/views/")
51
51
  # Remove "app/views" from view-translations since that doesn't get used in keys.
52
- @full_key.gsub!(/\Aapp\/views\//, "")
52
+ @full_key.delete_prefix!("app/views/")
53
53
  elsif @full_key.start_with?("app/controllers")
54
54
  # Remove "app/controllers" from controller-translations since that doesn't get used in keys.
55
55
  @full_key.gsub!(/\Aapp\/controllers(\/?)/, "")
56
56
  is_controller = true
57
57
  elsif @full_key.start_with?("app/cells")
58
- @full_key.gsub!(/\Aapp\/cells\//, "")
58
+ @full_key.delete_prefix!("app/cells/")
59
59
  elsif @full_key.start_with?("app/")
60
60
  # Remove "app" from controller- and helper-translations since that doesn't get used.
61
- @full_key.gsub!(/\Aapp\//, "")
61
+ @full_key.delete_prefix!("app/")
62
62
  end
63
63
 
64
64
  @full_key.tr!("/", ".")
@@ -66,7 +66,7 @@ private
66
66
  @full_key << file_key(@file_path)
67
67
  @full_key << ".#{@last_method}" if (is_mailer || is_controller) && @last_method && @method != "controller_t"
68
68
  @full_key << "."
69
- @full_key << @key.gsub(/\A\./, "")
69
+ @full_key << @key.delete_prefix(".")
70
70
  elsif @method == "I18n-js.t" || @method == "t" || @method == "helper_t" || @method == "controller_t"
71
71
  @full_key = @key
72
72
  else
@@ -81,10 +81,10 @@ private
81
81
  key = key.match(/\A(.+?)\./)[1]
82
82
 
83
83
  # Remove leading "_" from partials
84
- key = key.gsub(/\A_/, "")
84
+ key.delete_prefix!("_")
85
85
 
86
86
  # Remove '_controller' from controllers
87
- key = key.gsub(/_controller\Z/, "")
87
+ key.delete_suffix!("_controller")
88
88
 
89
89
  key
90
90
  end
@@ -1,8 +1,8 @@
1
1
  class PeakFlowUtils::HandlersFinderService < PeakFlowUtils::ApplicationService
2
- def execute
2
+ def perform
3
3
  handlers = []
4
4
 
5
- Dir.foreach("#{File.dirname(__FILE__)}/../../handlers/peak_flow_utils") do |file|
5
+ Dir.foreach("#{__dir__}/../../handlers/peak_flow_utils") do |file|
6
6
  match = file.match(/\A(.+)_handler\.rb\Z/)
7
7
  next unless match
8
8
 
@@ -1,5 +1,6 @@
1
1
  class PeakFlowUtils::ModelInspector
2
2
  attr_reader :clazz
3
+
3
4
  cattr_accessor :models_loaded
4
5
 
5
6
  # Yields a model-inspector for each model found in the application.
@@ -1,7 +1,7 @@
1
1
  class PeakFlowUtils::TranslationsParserService < PeakFlowUtils::ApplicationService
2
2
  attr_reader :db
3
3
 
4
- def execute
4
+ def perform
5
5
  PeakFlowUtils::DatabaseInitializerService.execute!
6
6
 
7
7
  cache_translations_in_dir(Rails.root.join("config/locales"))
@@ -103,11 +103,11 @@ private
103
103
  puts message.to_s if @debug # rubocop:disable Rails/Output
104
104
  end
105
105
 
106
- def execute_migrations
106
+ def perform_migrations
107
107
  require "baza_migrations"
108
108
 
109
109
  executor = BazaMigrations::MigrationsExecutor.new(db: @db)
110
- executor.add_dir "#{File.dirname(__FILE__)}/../../db/baza_translations_migrations"
110
+ executor.add_dir "#{__dir__}/../../db/baza_translations_migrations"
111
111
  executor.execute_migrations
112
112
  end
113
113
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  # This task detects and prints out the RSpec files for the current build group
4
4
 
5
- require "#{File.dirname(__FILE__)}/../lib/peak_flow_utils"
5
+ require "#{__dir__}/../lib/peak_flow_utils"
6
6
 
7
7
  args = {}
8
8
  ARGV.each do |arg|
data/config/routes.rb CHANGED
@@ -1,2 +1,6 @@
1
1
  PeakFlowUtils::Engine.routes.draw do
2
+ namespace :pings do
3
+ get "postgres_connections", to: "postgres_connections#count"
4
+ get "sidekiq", to: "sidekiq#index"
5
+ end
2
6
  end
@@ -4,8 +4,23 @@ require "array_enumerator"
4
4
  require "service_pattern"
5
5
 
6
6
  module PeakFlowUtils
7
- path = "#{File.dirname(__FILE__)}/peak_flow_utils"
7
+ path = "#{__dir__}/peak_flow_utils"
8
+ models_path = "#{__dir__}/peak_flow_utils/models"
8
9
 
10
+ autoload :Notifier, "#{path}/notifier"
11
+ autoload :NotifierErrorParser, "#{path}/notifier_error_parser"
12
+ autoload :NotifierRack, "#{path}/notifier_rack"
13
+ autoload :NotifierRails, "#{path}/notifier_rails"
14
+ autoload :NotifierResponse, "#{path}/notifier_response"
15
+ autoload :NotifierSidekiq, "#{path}/notifier_sidekiq"
9
16
  autoload :RspecHelper, "#{path}/rspec_helper"
10
17
  autoload :HandlerHelper, "#{path}/handler_helper"
18
+
19
+ autoload :ApplicationRecord, "#{models_path}/application_record"
20
+ autoload :Group, "#{models_path}/group"
21
+ autoload :HandlerText, "#{models_path}/handler_text"
22
+ autoload :Handler, "#{models_path}/handler"
23
+ autoload :ScannedFile, "#{models_path}/scanned_file"
24
+ autoload :TranslationKey, "#{models_path}/translation_key"
25
+ autoload :TranslationValue, "#{models_path}/translation_value"
11
26
  end
@@ -0,0 +1,83 @@
1
+ class PeakFlowUtils::Notifier
2
+ class FailedToReportError < RuntimeError; end
3
+ class NotConfiguredError < RuntimeError; end
4
+
5
+ attr_reader :auth_token
6
+
7
+ def self.configure(auth_token:)
8
+ @current = PeakFlowUtils::Notifier.new(auth_token: auth_token)
9
+ end
10
+
11
+ def self.current
12
+ raise PeakFlowUtils::Notifier::NotConfiguredError, "Hasn't been configured" if !@current && Rails.env.test?
13
+
14
+ @current
15
+ end
16
+
17
+ def self.notify(*args)
18
+ PeakFlowUtils::Notifier.current.notify(*args)
19
+ end
20
+
21
+ def initialize(auth_token:)
22
+ @auth_token = auth_token
23
+ end
24
+
25
+ def notify(error:, environment: nil, parameters: nil)
26
+ error_parser = PeakFlowUtils::NotifierErrorParser.new(
27
+ backtrace: error.backtrace,
28
+ environment: environment,
29
+ error: error
30
+ )
31
+
32
+ uri = URI("https://www.peakflow.io/errors/reports")
33
+
34
+ https = Net::HTTP.new(uri.host, uri.port)
35
+ https.use_ssl = true
36
+
37
+ data = {
38
+ auth_token: auth_token,
39
+ error: {
40
+ backtrace: error.backtrace,
41
+ environment: error_parser.cleaned_environment,
42
+ error_class: error.class.name,
43
+ file_path: error_parser.file_path,
44
+ line_number: error_parser.line_number,
45
+ message: error.message,
46
+ parameters: parameters,
47
+ remote_ip: error_parser.remote_ip,
48
+ url: error_parser.url,
49
+ user_agent: error_parser.user_agent
50
+ }
51
+ }
52
+
53
+ request = Net::HTTP::Post.new(uri.path)
54
+ request["Content-Type"] = "application/json"
55
+ request.body = JSON.generate(data)
56
+
57
+ response = https.request(request)
58
+
59
+ raise FailedToReportError, error_message_from_response(response) unless response.code == "200"
60
+
61
+ response_data = JSON.parse(response.body)
62
+
63
+ # Data not always present so dont use fetch
64
+ PeakFlowUtils::NotifierResponse.new(
65
+ bug_report_id: response_data["bug_report_id"],
66
+ bug_report_instance_id: response_data["bug_report_instance_id"],
67
+ project_id: response_data["project_id"],
68
+ project_slug: response_data["project_slug"],
69
+ url: response_data["url"]
70
+ )
71
+ end
72
+
73
+ def error_message_from_response(response)
74
+ message = "Couldn't report error to Peakflow (code #{response.code})"
75
+
76
+ if response["content-type"]&.starts_with?("application/json")
77
+ response_data = JSON.parse(response.body)
78
+ message << ": #{response_data.fetch("errors").join(". ")}" if response_data["errors"]
79
+ end
80
+
81
+ message
82
+ end
83
+ end
@@ -0,0 +1,53 @@
1
+ class PeakFlowUtils::NotifierErrorParser
2
+ attr_reader :backtrace, :environment, :error, :file_path, :line_number
3
+
4
+ def initialize(backtrace:, environment:, error:)
5
+ @backtrace = backtrace
6
+ @environment = environment || {}
7
+ @error = error
8
+
9
+ detect_file_path_and_line_number
10
+ end
11
+
12
+ def detect_file_path_and_line_number
13
+ backtrace.each do |trace|
14
+ match = trace.match(/^((.+)\.([A-z]{2,4})):(\d+)(:|$)/)
15
+ next unless match
16
+
17
+ file_path = match[1]
18
+ line_number = match[4].to_i
19
+
20
+ next if file_path.include?("/.rvm/")
21
+
22
+ @file_path ||= file_path
23
+ @line_number ||= line_number
24
+
25
+ break
26
+ end
27
+ end
28
+
29
+ def cleaned_environment
30
+ environment.reject do |key, _value|
31
+ key.start_with?("action_controller.", "action_dispatch.", "puma.", "rack.") || key == "warden"
32
+ end
33
+ end
34
+
35
+ def remote_ip
36
+ environment["HTTP_X_FORWARDED_FOR"] || environment["REMOTE_ADDR"]
37
+ end
38
+
39
+ def url
40
+ return unless environment["REQUEST_URI"]
41
+
42
+ url = "http"
43
+ url << "s" if environment["SERVER_PORT"] == 443 || environment["rack.url_scheme"] == "https" || environment["HTTPS"] == "on"
44
+ url << "://"
45
+ url << environment["HTTP_HOST"]
46
+ url << environment["REQUEST_URI"]
47
+ url
48
+ end
49
+
50
+ def user_agent
51
+ environment["HTTP_USER_AGENT"]
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ class PeakFlowUtils::NotifierRack
2
+ def initialize(app, options = {})
3
+ @app = app
4
+ @options = options
5
+ end
6
+
7
+ def call(env)
8
+ @app.call(env)
9
+ rescue Exception => e # rubocop:disable Lint/RescueException
10
+ controller = env["action_controller.instance"]
11
+ request = controller&.request
12
+ parameters = {}.merge(request.GET).merge(request.POST)
13
+
14
+ PeakFlowUtils::Notifier.notify(
15
+ environment: env,
16
+ error: e,
17
+ parameters: parameters
18
+ )
19
+
20
+ raise e
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ class PeakFlowUtils::NotifierRails
2
+ def self.configure
3
+ Rails.application.config.app_middleware.use PeakFlowUtils::NotifierRack
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class PeakFlowUtils::NotifierResponse
2
+ attr_reader :bug_report_id, :bug_report_instance_id, :project_id, :project_slug, :url
3
+
4
+ def initialize(bug_report_id:, bug_report_instance_id:, project_id:, project_slug:, url:)
5
+ @bug_report_id = bug_report_id
6
+ @bug_report_instance_id = bug_report_instance_id
7
+ @project_id = project_id
8
+ @project_slug = project_slug
9
+ @url = url
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class PeakFlowUtils::NotifierSidekiq
2
+ def self.configure
3
+ require "sidekiq"
4
+
5
+ Sidekiq.configure_server do |config|
6
+ config.error_handlers << proc do |error, _context|
7
+ PeakFlowUtils::Notifier.notify(error: error)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -118,7 +118,7 @@ class PeakFlowUtils::RspecHelper
118
118
  value1 = file1.fetch(:points)
119
119
  end
120
120
 
121
- if file2_data && file2_data && file2_data.fetch(:seconds) != 0.0 && file2_data.fetch(:seconds) != 0.0
121
+ if file2_data && file1_data && file2_data.fetch(:seconds) != 0.0 && file2_data.fetch(:seconds) != 0.0
122
122
  value2 = file2_data[:seconds]
123
123
  else
124
124
  value2 = file2.fetch(:points)
@@ -135,19 +135,20 @@ class PeakFlowUtils::RspecHelper
135
135
 
136
136
  private
137
137
 
138
- def dry_result_command
139
- command = "bundle exec rspec --dry-run --format json"
138
+ def dry_result
139
+ @dry_result ||= begin
140
+ require "json"
141
+ require "rspec/core"
140
142
 
141
- tags&.each do |tag|
142
- command << " --tag #{tag}"
143
- end
143
+ output_capture = StringIO.new
144
+ RSpec::Core::Runner.run(rspec_options, $stderr, output_capture)
144
145
 
145
- command
146
- end
146
+ result = ::JSON.parse(output_capture.string)
147
147
 
148
- def dry_result
149
- require "json"
150
- @dry_result ||= ::JSON.parse(`#{dry_result_command}`)
148
+ raise "No examples were found" if result.fetch("examples").empty?
149
+
150
+ result
151
+ end
151
152
  end
152
153
 
153
154
  def dry_file(path)
@@ -175,12 +176,7 @@ private
175
176
  end
176
177
 
177
178
  def ignore_type?(type)
178
- only_types && !only_types.include?(type)
179
- end
180
-
181
- def type_from_path(file_path)
182
- match = file_path.match(/^spec\/(.+?)\//)
183
- match[1] if match
179
+ only_types && !only_types.include?(type) # rubocop:disable Rails/NegateInclude:, Style/SafeNavigation
184
180
  end
185
181
 
186
182
  def points_from_type(type)
@@ -192,4 +188,22 @@ private
192
188
  1
193
189
  end
194
190
  end
191
+
192
+ def rspec_options
193
+ rspec_options = ["--dry-run", "--format", "json"]
194
+
195
+ tags&.each do |tag|
196
+ rspec_options += ["--tag", tag]
197
+ end
198
+
199
+ # Add the folder with all the specs, which is required when running programmatically
200
+ rspec_options << "spec"
201
+
202
+ rspec_options
203
+ end
204
+
205
+ def type_from_path(file_path)
206
+ match = file_path.match(/^spec\/(.+?)\//)
207
+ match[1] if match
208
+ end
195
209
  end
@@ -1,3 +1,3 @@
1
1
  module PeakFlowUtils
2
- VERSION = "0.1.8".freeze
2
+ VERSION = "0.1.13".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peak_flow_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-02 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,28 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: sqlite3
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: 1.0.0
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: 1.0.0
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: redis
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -133,11 +119,9 @@ files:
133
119
  - MIT-LICENSE
134
120
  - README.md
135
121
  - Rakefile
136
- - app/assets/config/peak_flow_utils_manifest.js
137
- - app/assets/javascripts/peak_flow_utils/application.js
138
- - app/assets/stylesheets/peak_flow_utils/application.css
139
122
  - app/controllers/peak_flow_utils/application_controller.rb
140
- - app/controllers/peak_flow_utils/pings/sidekiq_pings_controller.rb
123
+ - app/controllers/peak_flow_utils/pings/postgres_connections_controller.rb
124
+ - app/controllers/peak_flow_utils/pings/sidekiq_controller.rb
141
125
  - app/handlers/peak_flow_utils/application_handler.rb
142
126
  - app/handlers/peak_flow_utils/devise_handler.rb
143
127
  - app/handlers/peak_flow_utils/file_handler.rb
@@ -146,23 +130,7 @@ files:
146
130
  - app/handlers/peak_flow_utils/simple_form_handler.rb
147
131
  - app/handlers/peak_flow_utils/validations_handler.rb
148
132
  - app/handlers/peak_flow_utils/will_paginate_handler.rb
149
- - app/helpers/peak_flow_utils/application_helper.rb
150
- - app/jobs/peak_flow_utils/application_job.rb
151
- - app/mailers/peak_flow_utils/application_mailer.rb
152
- - app/migrations/20150902155200_create_translation_keys.rb
153
- - app/migrations/20150907070909_create_groups.rb
154
- - app/migrations/20150907090900_create_handlers.rb
155
- - app/migrations/20150908085500_create_translation_values.rb
156
- - app/migrations/20150908090800_create_handler_texts.rb
157
- - app/migrations/20160411190500_create_scanned_files.rb
158
- - app/migrations/peak_flow_utils/application_migration.rb
159
- - app/models/peak_flow_utils/application_record.rb
160
- - app/models/peak_flow_utils/group.rb
161
- - app/models/peak_flow_utils/handler.rb
162
- - app/models/peak_flow_utils/handler_text.rb
163
- - app/models/peak_flow_utils/scanned_file.rb
164
- - app/models/peak_flow_utils/translation_key.rb
165
- - app/models/peak_flow_utils/translation_value.rb
133
+ - app/services/peak_flow_utils/application_migration.rb
166
134
  - app/services/peak_flow_utils/application_service.rb
167
135
  - app/services/peak_flow_utils/attribute_service.rb
168
136
  - app/services/peak_flow_utils/configuration_service.rb
@@ -175,12 +143,30 @@ files:
175
143
  - app/services/peak_flow_utils/model_inspector.rb
176
144
  - app/services/peak_flow_utils/translation_service.rb
177
145
  - app/services/peak_flow_utils/translations_parser_service.rb
178
- - app/views/layouts/peak_flow_utils/application.html.erb
179
146
  - bin/peak_flow_rspec_files
180
147
  - config/routes.rb
181
148
  - lib/peak_flow_utils.rb
182
149
  - lib/peak_flow_utils/engine.rb
183
150
  - lib/peak_flow_utils/handler_helper.rb
151
+ - lib/peak_flow_utils/migrations/20150902155200_create_translation_keys.rb
152
+ - lib/peak_flow_utils/migrations/20150907070908_create_handlers.rb
153
+ - lib/peak_flow_utils/migrations/20150907070909_create_groups.rb
154
+ - lib/peak_flow_utils/migrations/20150908085500_create_translation_values.rb
155
+ - lib/peak_flow_utils/migrations/20150908090800_create_handler_texts.rb
156
+ - lib/peak_flow_utils/migrations/20160411190500_create_scanned_files.rb
157
+ - lib/peak_flow_utils/models/application_record.rb
158
+ - lib/peak_flow_utils/models/group.rb
159
+ - lib/peak_flow_utils/models/handler.rb
160
+ - lib/peak_flow_utils/models/handler_text.rb
161
+ - lib/peak_flow_utils/models/scanned_file.rb
162
+ - lib/peak_flow_utils/models/translation_key.rb
163
+ - lib/peak_flow_utils/models/translation_value.rb
164
+ - lib/peak_flow_utils/notifier.rb
165
+ - lib/peak_flow_utils/notifier_error_parser.rb
166
+ - lib/peak_flow_utils/notifier_rack.rb
167
+ - lib/peak_flow_utils/notifier_rails.rb
168
+ - lib/peak_flow_utils/notifier_response.rb
169
+ - lib/peak_flow_utils/notifier_sidekiq.rb
184
170
  - lib/peak_flow_utils/rspec_helper.rb
185
171
  - lib/peak_flow_utils/version.rb
186
172
  - lib/tasks/peak_flow_utils_tasks.rake
@@ -196,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
182
  requirements:
197
183
  - - ">="
198
184
  - !ruby/object:Gem::Version
199
- version: '0'
185
+ version: '2.5'
200
186
  required_rubygems_version: !ruby/object:Gem::Requirement
201
187
  requirements:
202
188
  - - ">="
@@ -1,2 +0,0 @@
1
- //= link_directory ../javascripts/peak_flow_utils .js
2
- //= link_directory ../stylesheets/peak_flow_utils .css
@@ -1,14 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
- //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require activestorage
14
- //= require_tree .
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
- * files in this directory. Styles in this file should be added after the last require_* statement.
11
- * It is generally better to create a new file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,10 +0,0 @@
1
- class PeakFlowUtils::Pings::SidekiqPings < PeakFlowUtils::ApplicationController
2
- def create
3
- sidekiq_queue = Sidekiq::Queue.new
4
-
5
- render json: {
6
- latency: sidekiq_queue.latency,
7
- queue_size: sidekiq_queue.size
8
- }
9
- end
10
- end
@@ -1,2 +0,0 @@
1
- module PeakFlowUtils::ApplicationHelper
2
- end
@@ -1,2 +0,0 @@
1
- class PeakFlowUtils::ApplicationJob < ActiveJob::Base
2
- end
@@ -1,4 +0,0 @@
1
- class PeakFlowUtils::ApplicationMailer < ActionMailer::Base
2
- default from: "from@example.com"
3
- layout "mailer"
4
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Peak flow utils</title>
5
- <%= stylesheet_link_tag "peak_flow_utils/application", media: "all" %>
6
- <%= javascript_include_tag "peak_flow_utils/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>