peak_flow_utils 0.1.10 → 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/handlers/peak_flow_utils/validations_handler.rb +3 -3
- data/{lib/peak_flow_utils/migrations → app/services}/peak_flow_utils/application_migration.rb +0 -0
- 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/model_inspector.rb +1 -0
- data/lib/peak_flow_utils.rb +6 -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 +2 -2
- data/lib/peak_flow_utils/version.rb +1 -1
- metadata +10 -18
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
|
|
@@ -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}"
|
data/{lib/peak_flow_utils/migrations → app/services}/peak_flow_utils/application_migration.rb
RENAMED
File without changes
|
@@ -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
|
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
|
@@ -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
|
@@ -118,7 +118,7 @@ class PeakFlowUtils::RspecHelper
|
|
118
118
|
value1 = file1.fetch(:points)
|
119
119
|
end
|
120
120
|
|
121
|
-
if file2_data &&
|
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)
|
@@ -175,7 +175,7 @@ private
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def ignore_type?(type)
|
178
|
-
only_types && !only_types.include?(type)
|
178
|
+
only_types && !only_types.include?(type) # rubocop:disable Rails/NegateInclude:, Style/SafeNavigation
|
179
179
|
end
|
180
180
|
|
181
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: 2020-
|
11
|
+
date: 2020-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
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'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: redis
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,6 +142,7 @@ files:
|
|
156
142
|
- app/models/peak_flow_utils/scanned_file.rb
|
157
143
|
- app/models/peak_flow_utils/translation_key.rb
|
158
144
|
- app/models/peak_flow_utils/translation_value.rb
|
145
|
+
- app/services/peak_flow_utils/application_migration.rb
|
159
146
|
- app/services/peak_flow_utils/application_service.rb
|
160
147
|
- app/services/peak_flow_utils/attribute_service.rb
|
161
148
|
- app/services/peak_flow_utils/configuration_service.rb
|
@@ -180,7 +167,12 @@ files:
|
|
180
167
|
- lib/peak_flow_utils/migrations/20150908085500_create_translation_values.rb
|
181
168
|
- lib/peak_flow_utils/migrations/20150908090800_create_handler_texts.rb
|
182
169
|
- lib/peak_flow_utils/migrations/20160411190500_create_scanned_files.rb
|
183
|
-
- lib/peak_flow_utils/
|
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
|
184
176
|
- lib/peak_flow_utils/rspec_helper.rb
|
185
177
|
- lib/peak_flow_utils/version.rb
|
186
178
|
- lib/tasks/peak_flow_utils_tasks.rake
|
@@ -196,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
188
|
requirements:
|
197
189
|
- - ">="
|
198
190
|
- !ruby/object:Gem::Version
|
199
|
-
version: '
|
191
|
+
version: '2.5'
|
200
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
193
|
requirements:
|
202
194
|
- - ">="
|