peak_flow_utils 0.1.6 → 0.1.11
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 +4 -4
 - data/README.md +30 -5
 - data/app/controllers/peak_flow_utils/pings/sidekiq_pings_controller.rb +1 -1
 - data/app/handlers/peak_flow_utils/devise_handler.rb +2 -2
 - data/app/handlers/peak_flow_utils/validations_handler.rb +3 -3
 - data/app/{migrations → services}/peak_flow_utils/application_migration.rb +0 -0
 - data/app/services/peak_flow_utils/database_initializer_service.rb +2 -2
 - data/app/services/peak_flow_utils/erb_inspector/file_inspector.rb +4 -4
 - data/app/services/peak_flow_utils/erb_inspector/translation_inspector.rb +7 -7
 - data/app/services/peak_flow_utils/handlers_finder_service.rb +1 -1
 - data/app/services/peak_flow_utils/model_inspector.rb +2 -1
 - data/app/services/peak_flow_utils/translations_parser_service.rb +1 -1
 - data/lib/peak_flow_utils.rb +6 -0
 - data/{app → lib/peak_flow_utils}/migrations/20150902155200_create_translation_keys.rb +0 -0
 - data/{app → lib/peak_flow_utils}/migrations/20150907070909_create_groups.rb +0 -0
 - data/{app → lib/peak_flow_utils}/migrations/20150907090900_create_handlers.rb +0 -0
 - data/{app → lib/peak_flow_utils}/migrations/20150908085500_create_translation_values.rb +0 -0
 - data/{app → lib/peak_flow_utils}/migrations/20150908090800_create_handler_texts.rb +0 -0
 - data/{app → lib/peak_flow_utils}/migrations/20160411190500_create_scanned_files.rb +0 -0
 - data/lib/peak_flow_utils/notifier.rb +61 -0
 - data/lib/peak_flow_utils/notifier_error_parser.rb +53 -0
 - data/lib/peak_flow_utils/notifier_rack.rb +22 -0
 - data/lib/peak_flow_utils/notifier_rails.rb +5 -0
 - data/lib/peak_flow_utils/notifier_response.rb +7 -0
 - data/lib/peak_flow_utils/notifier_sidekiq.rb +11 -0
 - data/lib/peak_flow_utils/rspec_helper.rb +8 -4
 - data/lib/peak_flow_utils/version.rb +1 -1
 - metadata +17 -11
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1bdc19548c94f5a84768b360d892e622d4a43e2b93aabd2211ff01aaa90aee1f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9144161819e38594b3b8adefd74d9f60c7b9de2c1e5873c5f007058d4ea74eb5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: bb753bd4bda442fae033de2b2d1f05a3815f0584ca54a263ffc2d8e2647692cb3af6f40289c7989301087ff0d44cf727681e4a370dc50fba14bd504a71457f57
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0b8b67efb910799b5a78dda78c12f2e85ac4e45144493d662babafa03dc328f40f2bf4814030fab49072716b5285976c965460e13fc25f9c8965217933b452a2
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,14 +1,12 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #  
     | 
| 
       2 
     | 
    
         
            -
            Short description and motivation.
         
     | 
| 
      
 1 
     | 
    
         
            +
            # PeakflowUtils
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       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  
     | 
| 
      
 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 
     | 
    
         | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # rubocop:disable  
     | 
| 
      
 1 
     | 
    
         
            +
            # rubocop:disable Layout/LineLength
         
     | 
| 
       2 
2 
     | 
    
         
             
            class PeakFlowUtils::DeviseHandler < PeakFlowUtils::ApplicationHandler
         
     | 
| 
       3 
3 
     | 
    
         
             
              def enabled?
         
     | 
| 
       4 
4 
     | 
    
         
             
                ::Object.const_defined?(:Devise)
         
     | 
| 
         @@ -123,4 +123,4 @@ private 
     | 
|
| 
       123 
123 
     | 
    
         
             
                }
         
     | 
| 
       124 
124 
     | 
    
         
             
              end
         
     | 
| 
       125 
125 
     | 
    
         
             
            end
         
     | 
| 
       126 
     | 
    
         
            -
            # rubocop:enable  
     | 
| 
      
 126 
     | 
    
         
            +
            # rubocop:enable Layout/LineLength
         
     | 
| 
         @@ -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}"
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class PeakFlowUtils::DatabaseInitializerService < PeakFlowUtils::ApplicationService
         
     | 
| 
       2 
2 
     | 
    
         
             
              def execute
         
     | 
| 
       3 
     | 
    
         
            -
                path = File.realpath("#{File.dirname(__FILE__)} 
     | 
| 
      
 3 
     | 
    
         
            +
                path = File.realpath("#{File.dirname(__FILE__)}/../../../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|
         
     | 
| 
         @@ -16,7 +16,7 @@ class PeakFlowUtils::DatabaseInitializerService < PeakFlowUtils::ApplicationServ 
     | 
|
| 
       16 
16 
     | 
    
         
             
                  register_migration_migrated(version)
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
      
 19 
     | 
    
         
            +
                succeed!
         
     | 
| 
       20 
20 
     | 
    
         
             
              end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
            private
         
     | 
| 
         @@ -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( 
     | 
| 
      
 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( 
     | 
| 
      
 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( 
     | 
| 
      
 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(/'([ 
     | 
| 
      
 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? &&  
     | 
| 
      
 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. 
     | 
| 
      
 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. 
     | 
| 
      
 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. 
     | 
| 
      
 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. 
     | 
| 
      
 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 
     | 
| 
      
 84 
     | 
    
         
            +
                key.delete_prefix!("_")
         
     | 
| 
       85 
85 
     | 
    
         | 
| 
       86 
86 
     | 
    
         
             
                # Remove '_controller' from controllers
         
     | 
| 
       87 
     | 
    
         
            -
                key 
     | 
| 
      
 87 
     | 
    
         
            +
                key.delete_suffix!("_controller")
         
     | 
| 
       88 
88 
     | 
    
         | 
| 
       89 
89 
     | 
    
         
             
                key
         
     | 
| 
       90 
90 
     | 
    
         
             
              end
         
     | 
| 
         @@ -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.
         
     | 
| 
         @@ -122,7 +123,7 @@ class PeakFlowUtils::ModelInspector 
     | 
|
| 
       122 
123 
     | 
    
         | 
| 
       123 
124 
     | 
    
         
             
              # Loads models for the given app-directory (Rails-root or engine).
         
     | 
| 
       124 
125 
     | 
    
         
             
              def self.load_models_for(root)
         
     | 
| 
       125 
     | 
    
         
            -
                Dir.glob("#{root}/app/models/**/*.rb") do |model_path|
         
     | 
| 
      
 126 
     | 
    
         
            +
                Dir.glob("#{root}/app/models/**/*.rb").sort.each do |model_path|
         
     | 
| 
       126 
127 
     | 
    
         
             
                  require model_path
         
     | 
| 
       127 
128 
     | 
    
         
             
                rescue StandardError => e
         
     | 
| 
       128 
129 
     | 
    
         
             
                  warn "Could not load model in #{model_path}"
         
     | 
    
        data/lib/peak_flow_utils.rb
    CHANGED
    
    | 
         @@ -6,6 +6,12 @@ require "service_pattern" 
     | 
|
| 
       6 
6 
     | 
    
         
             
            module PeakFlowUtils
         
     | 
| 
       7 
7 
     | 
    
         
             
              path = "#{File.dirname(__FILE__)}/peak_flow_utils"
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
              autoload :Notifier, "#{path}/notifier"
         
     | 
| 
      
 10 
     | 
    
         
            +
              autoload :NotifierErrorParser, "#{path}/notifier_error_parser"
         
     | 
| 
      
 11 
     | 
    
         
            +
              autoload :NotifierRack, "#{path}/notifier_rack"
         
     | 
| 
      
 12 
     | 
    
         
            +
              autoload :NotifierRails, "#{path}/notifier_rails"
         
     | 
| 
      
 13 
     | 
    
         
            +
              autoload :NotifierResponse, "#{path}/notifier_response"
         
     | 
| 
      
 14 
     | 
    
         
            +
              autoload :NotifierSidekiq, "#{path}/notifier_sidekiq"
         
     | 
| 
       9 
15 
     | 
    
         
             
              autoload :RspecHelper, "#{path}/rspec_helper"
         
     | 
| 
       10 
16 
     | 
    
         
             
              autoload :HandlerHelper, "#{path}/handler_helper"
         
     | 
| 
       11 
17 
     | 
    
         
             
            end
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -0,0 +1,61 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class PeakFlowUtils::Notifier
         
     | 
| 
      
 2 
     | 
    
         
            +
              class NotConfiguredError < RuntimeError; end
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              attr_reader :auth_token
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def self.configure(auth_token:)
         
     | 
| 
      
 7 
     | 
    
         
            +
                @current = PeakFlowUtils::Notifier.new(auth_token: auth_token)
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def self.current
         
     | 
| 
      
 11 
     | 
    
         
            +
                raise PeakFlowUtils::Notifier::NotConfiguredError, "Hasn't been configured" unless @current
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                @current
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              def self.notify(*args)
         
     | 
| 
      
 17 
     | 
    
         
            +
                PeakFlowUtils::Notifier.current.notify(*args)
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              def initialize(auth_token:)
         
     | 
| 
      
 21 
     | 
    
         
            +
                @auth_token = auth_token
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              def notify(error:, environment: nil, parameters: nil)
         
     | 
| 
      
 25 
     | 
    
         
            +
                error_parser = PeakFlowUtils::NotifierErrorParser.new(
         
     | 
| 
      
 26 
     | 
    
         
            +
                  backtrace: error.backtrace,
         
     | 
| 
      
 27 
     | 
    
         
            +
                  environment: environment,
         
     | 
| 
      
 28 
     | 
    
         
            +
                  error: error
         
     | 
| 
      
 29 
     | 
    
         
            +
                )
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                uri = URI("https://www.peakflow.io/errors/reports")
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                https = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
      
 34 
     | 
    
         
            +
                https.use_ssl = true
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                data = {
         
     | 
| 
      
 37 
     | 
    
         
            +
                  auth_token: auth_token,
         
     | 
| 
      
 38 
     | 
    
         
            +
                  error: {
         
     | 
| 
      
 39 
     | 
    
         
            +
                    backtrace: error.backtrace,
         
     | 
| 
      
 40 
     | 
    
         
            +
                    environment: error_parser.cleaned_environment,
         
     | 
| 
      
 41 
     | 
    
         
            +
                    error_class: error.class.name,
         
     | 
| 
      
 42 
     | 
    
         
            +
                    file_path: error_parser.file_path,
         
     | 
| 
      
 43 
     | 
    
         
            +
                    line_number: error_parser.line_number,
         
     | 
| 
      
 44 
     | 
    
         
            +
                    message: error.message,
         
     | 
| 
      
 45 
     | 
    
         
            +
                    parameters: parameters,
         
     | 
| 
      
 46 
     | 
    
         
            +
                    remote_ip: error_parser.remote_ip,
         
     | 
| 
      
 47 
     | 
    
         
            +
                    url: error_parser.url,
         
     | 
| 
      
 48 
     | 
    
         
            +
                    user_agent: error_parser.user_agent
         
     | 
| 
      
 49 
     | 
    
         
            +
                  }
         
     | 
| 
      
 50 
     | 
    
         
            +
                }
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                request = Net::HTTP::Post.new(uri.path)
         
     | 
| 
      
 53 
     | 
    
         
            +
                request["Content-Type"] = "application/json"
         
     | 
| 
      
 54 
     | 
    
         
            +
                request.body = JSON.generate(data)
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                response = https.request(request)
         
     | 
| 
      
 57 
     | 
    
         
            +
                response_data = JSON.parse(response.body)
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                PeakFlowUtils::NotifierResponse.new(url: response_data["url"]) # URL not always present so dont use fetch
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
            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
         
     | 
| 
         @@ -59,8 +59,6 @@ class PeakFlowUtils::RspecHelper 
     | 
|
| 
       59 
59 
     | 
    
         
             
              def group_files
         
     | 
| 
       60 
60 
     | 
    
         
             
                return @group_files if @group_files
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
                # Sort them so that they are sorted by file path in three groups so each group have an equal amount of controller specs, features specs and so on
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
62 
     | 
    
         
             
                sorted_files.each do |file|
         
     | 
| 
       65 
63 
     | 
    
         
             
                  file_path = file.fetch(:path)
         
     | 
| 
       66 
64 
     | 
    
         
             
                  file_data = example_file(file_path) if example_data_exists?
         
     | 
| 
         @@ -105,6 +103,7 @@ class PeakFlowUtils::RspecHelper 
     | 
|
| 
       105 
103 
     | 
    
         
             
                end
         
     | 
| 
       106 
104 
     | 
    
         
             
              end
         
     | 
| 
       107 
105 
     | 
    
         | 
| 
      
 106 
     | 
    
         
            +
              # Sort them so that they are sorted by file path in three groups so each group have an equal amount of controller specs, features specs and so on
         
     | 
| 
       108 
107 
     | 
    
         
             
              def sorted_files
         
     | 
| 
       109 
108 
     | 
    
         
             
                files.values.sort do |file1, file2|
         
     | 
| 
       110 
109 
     | 
    
         
             
                  file1_path = file1.fetch(:path)
         
     | 
| 
         @@ -119,12 +118,17 @@ class PeakFlowUtils::RspecHelper 
     | 
|
| 
       119 
118 
     | 
    
         
             
                    value1 = file1.fetch(:points)
         
     | 
| 
       120 
119 
     | 
    
         
             
                  end
         
     | 
| 
       121 
120 
     | 
    
         | 
| 
       122 
     | 
    
         
            -
                  if file2_data &&  
     | 
| 
      
 121 
     | 
    
         
            +
                  if file2_data && file1_data && file2_data.fetch(:seconds) != 0.0 && file2_data.fetch(:seconds) != 0.0
         
     | 
| 
       123 
122 
     | 
    
         
             
                    value2 = file2_data[:seconds]
         
     | 
| 
       124 
123 
     | 
    
         
             
                  else
         
     | 
| 
       125 
124 
     | 
    
         
             
                    value2 = file2.fetch(:points)
         
     | 
| 
       126 
125 
     | 
    
         
             
                  end
         
     | 
| 
       127 
126 
     | 
    
         | 
| 
      
 127 
     | 
    
         
            +
                  if value1 == value2
         
     | 
| 
      
 128 
     | 
    
         
            +
                    value2 = file1_path
         
     | 
| 
      
 129 
     | 
    
         
            +
                    value1 = file2_path
         
     | 
| 
      
 130 
     | 
    
         
            +
                  end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
       128 
132 
     | 
    
         
             
                  value2 <=> value1
         
     | 
| 
       129 
133 
     | 
    
         
             
                end
         
     | 
| 
       130 
134 
     | 
    
         
             
              end
         
     | 
| 
         @@ -171,7 +175,7 @@ private 
     | 
|
| 
       171 
175 
     | 
    
         
             
              end
         
     | 
| 
       172 
176 
     | 
    
         | 
| 
       173 
177 
     | 
    
         
             
              def ignore_type?(type)
         
     | 
| 
       174 
     | 
    
         
            -
                only_types && !only_types.include?(type)
         
     | 
| 
      
 178 
     | 
    
         
            +
                only_types && !only_types.include?(type) # rubocop:disable Rails/NegateInclude:, Style/SafeNavigation
         
     | 
| 
       175 
179 
     | 
    
         
             
              end
         
     | 
| 
       176 
180 
     | 
    
         | 
| 
       177 
181 
     | 
    
         
             
              def type_from_path(file_path)
         
     | 
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.11
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - kaspernj
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-11-23 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -135,13 +135,6 @@ files: 
     | 
|
| 
       135 
135 
     | 
    
         
             
            - app/helpers/peak_flow_utils/application_helper.rb
         
     | 
| 
       136 
136 
     | 
    
         
             
            - app/jobs/peak_flow_utils/application_job.rb
         
     | 
| 
       137 
137 
     | 
    
         
             
            - app/mailers/peak_flow_utils/application_mailer.rb
         
     | 
| 
       138 
     | 
    
         
            -
            - app/migrations/20150902155200_create_translation_keys.rb
         
     | 
| 
       139 
     | 
    
         
            -
            - app/migrations/20150907070909_create_groups.rb
         
     | 
| 
       140 
     | 
    
         
            -
            - app/migrations/20150907090900_create_handlers.rb
         
     | 
| 
       141 
     | 
    
         
            -
            - app/migrations/20150908085500_create_translation_values.rb
         
     | 
| 
       142 
     | 
    
         
            -
            - app/migrations/20150908090800_create_handler_texts.rb
         
     | 
| 
       143 
     | 
    
         
            -
            - app/migrations/20160411190500_create_scanned_files.rb
         
     | 
| 
       144 
     | 
    
         
            -
            - app/migrations/peak_flow_utils/application_migration.rb
         
     | 
| 
       145 
138 
     | 
    
         
             
            - app/models/peak_flow_utils/application_record.rb
         
     | 
| 
       146 
139 
     | 
    
         
             
            - app/models/peak_flow_utils/group.rb
         
     | 
| 
       147 
140 
     | 
    
         
             
            - app/models/peak_flow_utils/handler.rb
         
     | 
| 
         @@ -149,6 +142,7 @@ files: 
     | 
|
| 
       149 
142 
     | 
    
         
             
            - app/models/peak_flow_utils/scanned_file.rb
         
     | 
| 
       150 
143 
     | 
    
         
             
            - app/models/peak_flow_utils/translation_key.rb
         
     | 
| 
       151 
144 
     | 
    
         
             
            - app/models/peak_flow_utils/translation_value.rb
         
     | 
| 
      
 145 
     | 
    
         
            +
            - app/services/peak_flow_utils/application_migration.rb
         
     | 
| 
       152 
146 
     | 
    
         
             
            - app/services/peak_flow_utils/application_service.rb
         
     | 
| 
       153 
147 
     | 
    
         
             
            - app/services/peak_flow_utils/attribute_service.rb
         
     | 
| 
       154 
148 
     | 
    
         
             
            - app/services/peak_flow_utils/configuration_service.rb
         
     | 
| 
         @@ -167,6 +161,18 @@ files: 
     | 
|
| 
       167 
161 
     | 
    
         
             
            - lib/peak_flow_utils.rb
         
     | 
| 
       168 
162 
     | 
    
         
             
            - lib/peak_flow_utils/engine.rb
         
     | 
| 
       169 
163 
     | 
    
         
             
            - lib/peak_flow_utils/handler_helper.rb
         
     | 
| 
      
 164 
     | 
    
         
            +
            - lib/peak_flow_utils/migrations/20150902155200_create_translation_keys.rb
         
     | 
| 
      
 165 
     | 
    
         
            +
            - lib/peak_flow_utils/migrations/20150907070909_create_groups.rb
         
     | 
| 
      
 166 
     | 
    
         
            +
            - lib/peak_flow_utils/migrations/20150907090900_create_handlers.rb
         
     | 
| 
      
 167 
     | 
    
         
            +
            - lib/peak_flow_utils/migrations/20150908085500_create_translation_values.rb
         
     | 
| 
      
 168 
     | 
    
         
            +
            - lib/peak_flow_utils/migrations/20150908090800_create_handler_texts.rb
         
     | 
| 
      
 169 
     | 
    
         
            +
            - lib/peak_flow_utils/migrations/20160411190500_create_scanned_files.rb
         
     | 
| 
      
 170 
     | 
    
         
            +
            - lib/peak_flow_utils/notifier.rb
         
     | 
| 
      
 171 
     | 
    
         
            +
            - lib/peak_flow_utils/notifier_error_parser.rb
         
     | 
| 
      
 172 
     | 
    
         
            +
            - lib/peak_flow_utils/notifier_rack.rb
         
     | 
| 
      
 173 
     | 
    
         
            +
            - lib/peak_flow_utils/notifier_rails.rb
         
     | 
| 
      
 174 
     | 
    
         
            +
            - lib/peak_flow_utils/notifier_response.rb
         
     | 
| 
      
 175 
     | 
    
         
            +
            - lib/peak_flow_utils/notifier_sidekiq.rb
         
     | 
| 
       170 
176 
     | 
    
         
             
            - lib/peak_flow_utils/rspec_helper.rb
         
     | 
| 
       171 
177 
     | 
    
         
             
            - lib/peak_flow_utils/version.rb
         
     | 
| 
       172 
178 
     | 
    
         
             
            - lib/tasks/peak_flow_utils_tasks.rake
         
     | 
| 
         @@ -182,14 +188,14 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       182 
188 
     | 
    
         
             
              requirements:
         
     | 
| 
       183 
189 
     | 
    
         
             
              - - ">="
         
     | 
| 
       184 
190 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       185 
     | 
    
         
            -
                  version: ' 
     | 
| 
      
 191 
     | 
    
         
            +
                  version: '2.5'
         
     | 
| 
       186 
192 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       187 
193 
     | 
    
         
             
              requirements:
         
     | 
| 
       188 
194 
     | 
    
         
             
              - - ">="
         
     | 
| 
       189 
195 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       190 
196 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       191 
197 
     | 
    
         
             
            requirements: []
         
     | 
| 
       192 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 198 
     | 
    
         
            +
            rubygems_version: 3.0.6
         
     | 
| 
       193 
199 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       194 
200 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       195 
201 
     | 
    
         
             
            summary: Utilities to be used with PeakFlow.
         
     |