usps-support 0.2.12 → 0.2.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0de6810ba31862cf10f201d98eae763ef3ec25418fdf16b56366aff389b6adc
4
- data.tar.gz: 9468d6207912e23c9175440cb18594f13ab150c01bc1ea6159d3a42be14356ae
3
+ metadata.gz: 1a1f549d644684483d69c041d99543a3a8625bb25a68cf358590294cbc392913
4
+ data.tar.gz: 98b7e0b626a2a16ff6d0cd160e84c95a7bf158bbb6541cf50f34dc6a31a8b819
5
5
  SHA512:
6
- metadata.gz: e62531e51b9dc05a8cb81ad8ed7434216c7979453d31a418d64fe9c073baec8c34916cddd162b73e2b5c5b1c7a8dc4a12773a491e9af996b382aed3dad1e3eb2
7
- data.tar.gz: 9631728af38c4dba0c0c05e15dd20a03c870e4ce7678eb19eb5ed080fe15f7112459795cc4afb2371a76d559c8753d5d4fd2866a37a0e9a56071efa547fae307
6
+ metadata.gz: f888d620eb8d2ca0d8fc398a7343fe97e439554ef4fea4a8855e241f6bea9fe30a99f7b3b56a1adec989c846786d6b605819f5dc778a53250d06f3c1ecc1e753
7
+ data.tar.gz: 8a625b98f21a8d6bd37d05a85a6e0922d0e2fa6ab27b90e07cd2d3329e6fa3472970acc51eb99c563dbacc6d161126b58b21ce8ddf4344c166bcf122aba69475
@@ -0,0 +1,84 @@
1
+ module Usps::Support::Lib::SimpleCov
2
+ # Parser for converting hash filter definition into individual coverage filters
3
+ #
4
+ # Example config:
5
+ #
6
+ # {
7
+ # ignored_category_header: {
8
+ # spec: '*',
9
+ # app: {
10
+ # controllers: %w[example_1],
11
+ # helpers: 'example_2',
12
+ # models: {
13
+ # members: %w[example_3],
14
+ # _: %w[example_4]
15
+ # }
16
+ # }
17
+ # }
18
+ # }
19
+ #
20
+ # This config would generate the following coverage filters:
21
+ #
22
+ # - `/spec`
23
+ # - `/app/controllers/example_1.rb`
24
+ # - `/app/helpers/example_2.rb`
25
+ # - `/app/models/members/example_3.rb`
26
+ # - `/app/models/example_4.rb`
27
+ #
28
+ class FiltersParser
29
+ attr_reader :filters_config
30
+
31
+ def self.paths(...) = new(...).paths
32
+
33
+ def initialize(filters_config)
34
+ @filters_config = filters_config
35
+ @dir = []
36
+ @paths = []
37
+ end
38
+
39
+ def paths
40
+ return @paths if @paths.any?
41
+
42
+ filters_config.each_value { parse_data(it) }
43
+
44
+ @paths
45
+ end
46
+
47
+ private
48
+
49
+ def parse_data(data)
50
+ case data
51
+ when '*' then filter_dir
52
+ when String then filter_file(data)
53
+ when Array then data.each { filter_file(it) }
54
+ when Hash then walk(data)
55
+ else
56
+ raise "Unrecognized filter format: #{data.inspect}"
57
+ end
58
+ end
59
+
60
+ def walk(hash)
61
+ hash.each do |dir, sub_data|
62
+ with(dir) { parse_data(sub_data) }
63
+ end
64
+ end
65
+
66
+ def with(dir)
67
+ @dir << dir.to_s
68
+ yield
69
+ @dir.pop
70
+ end
71
+
72
+ def filter_dir
73
+ @paths << dir_path
74
+ end
75
+
76
+ def filter_file(filename)
77
+ @paths << File.join(dir_path, "#{filename}.rb")
78
+ end
79
+
80
+ def dir_path
81
+ "/#{File.join(@dir)}".sub(%r{/_}, '') if @dir.any?
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,49 @@
1
+ module Usps::Support::Lib::SimpleCov
2
+ # Simple coverage formatter to display paths of any uncovered lines
3
+ #
4
+ # Intended to make it quicker to know what was uncovered, especially when
5
+ # running in GitHub Actions
6
+ #
7
+ # rubocop:disable Rails/Output
8
+ class UncoveredLinesFormatter
9
+ attr_reader :uncovered_files
10
+
11
+ def format(result)
12
+ @uncovered_files = result.files.reject { it.missed_lines.empty? }
13
+ return unless uncovered_files.any?
14
+
15
+ puts 'Uncovered lines:'
16
+ uncovered_files.each { report(it) }
17
+ end
18
+
19
+ private
20
+
21
+ def report(file)
22
+ missed = pad(file.missed_lines.size)
23
+ total = pad(file.lines_of_code)
24
+ percent = file.covered_percent.round(2).to_s.rjust(5, ' ')
25
+
26
+ puts " [#{missed} / #{total} : #{percent}%] #{file.filename}"
27
+ puts " Lines: #{line_number_ranges(file).join(', ')}"
28
+ end
29
+
30
+ def pad(number) = number.to_s.rjust(max_line_count_length, ' ')
31
+
32
+ def max_line_count_length
33
+ @max_line_count_length ||= uncovered_files.map(&:lines_of_code).max.to_s.length
34
+ end
35
+
36
+ def line_number_ranges(file)
37
+ file
38
+ .missed_lines
39
+ .map(&:line_number)
40
+ .chunk
41
+ .with_index { |number, index| number - index }
42
+ .index_with do |group|
43
+ first, *, last = group
44
+ last.nil? ? first : "#{first}-#{last}"
45
+ end
46
+ end
47
+ end
48
+ # rubocop:enable Rails/Output
49
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Usps::Support::Lib
4
+ # SimpleCov extensions
5
+ #
6
+ module SimpleCov; end
7
+ end
8
+
9
+ require_relative 'simple_cov/filters_parser'
10
+ require_relative 'simple_cov/uncovered_lines_formatter'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Shared Rails libraries
4
+ #
5
+ module Usps::Support::Lib; end
6
+
7
+ require_relative 'lib/simple_cov'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Support
5
- VERSION = '0.2.12'
5
+ VERSION = '0.2.14'
6
6
  end
7
7
  end
data/lib/usps/support.rb CHANGED
@@ -12,6 +12,7 @@ end
12
12
 
13
13
  require_relative 'support/helpers'
14
14
  require_relative 'support/models'
15
+ require_relative 'support/lib'
15
16
 
16
17
  # :nocov:
17
18
  require 'usps/support/railtie' if defined?(Rails)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -29,28 +29,28 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.11.31
32
+ version: 0.11.34
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.11.31
39
+ version: 0.11.34
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: usps-jwt_auth
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 1.0.0
46
+ version: 1.0.5
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 1.0.0
53
+ version: 1.0.5
54
54
  description: Shared support for USPS Rails applications
55
55
  email:
56
56
  - jsfiander@gmail.com
@@ -69,6 +69,10 @@ files:
69
69
  - lib/usps/support/helpers/git_helper.rb
70
70
  - lib/usps/support/helpers/react_helper.rb
71
71
  - lib/usps/support/helpers/scss_helper.rb
72
+ - lib/usps/support/lib.rb
73
+ - lib/usps/support/lib/simple_cov.rb
74
+ - lib/usps/support/lib/simple_cov/filters_parser.rb
75
+ - lib/usps/support/lib/simple_cov/uncovered_lines_formatter.rb
72
76
  - lib/usps/support/models.rb
73
77
  - lib/usps/support/models/dynamo_db.rb
74
78
  - lib/usps/support/models/git_hub.rb