swagcov 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/swagcov.rb +1 -0
- data/lib/swagcov/coverage.rb +5 -30
- data/lib/swagcov/dotfile.rb +52 -0
- data/lib/swagcov/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83f05163f3408b08db9f9810e5eb82a4285877d9e7b7af60a83e44386eab5c04
|
4
|
+
data.tar.gz: 76b1bf03e51bc42e516f5b77536d1ae38685dd642823094a0ac8e67fa8c67ac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82610986597a8a832173354fb452a4d63c7c0a22a342ec10fd2ac6bcb3eef845d306c6d37225ac837b22febcb12a0ba093167b71d3acc94aaabb8394789b77a7
|
7
|
+
data.tar.gz: a1cdf7691af9fce07dfc50711a748bcbfe903ef0f5f5b94e3d1b3d7fd605ac125de92db23121a8ccdb8622494bfba431f7f3710e55f6392a20160e5c2bfd4e4f
|
data/README.md
CHANGED
@@ -77,13 +77,17 @@ bundle
|
|
77
77
|
- Ensure you have access to publish on [rubygems](https://rubygems.org/gems/swagcov).
|
78
78
|
- Update [CHANGELOG](https://github.com/smridge/swagcov/blob/main/CHANGELOG.md).
|
79
79
|
- Update [`VERSION`](https://github.com/smridge/swagcov/blob/main/lib/swagcov/version.rb).
|
80
|
+
- Commit changes to `main` branch locally.
|
80
81
|
- Run: `rake release`
|
81
82
|
- This command builds the gem, creates a tag and publishes to rubygems, see [bundler docs](https://bundler.io/guides/creating_gem.html#releasing-the-gem).
|
82
83
|
|
83
84
|
## TODO
|
84
85
|
- Add specs
|
85
86
|
- Test against different rails versions
|
87
|
+
- Create Sandbox Apps for Rails 5 & 6
|
86
88
|
- Add autogeneration of ignore paths
|
89
|
+
- Add `CONTRIBUTING.md`
|
90
|
+
- Add GitHub Actions for specs/linting
|
87
91
|
|
88
92
|
## Credit
|
89
93
|
To [@lonelyelk](https://github.com/lonelyelk) for initial development!
|
data/lib/swagcov.rb
CHANGED
data/lib/swagcov/coverage.rb
CHANGED
@@ -9,6 +9,7 @@ module Swagcov
|
|
9
9
|
@routes_not_covered = []
|
10
10
|
@routes_covered = []
|
11
11
|
@routes_ignored = []
|
12
|
+
@dotfile = Swagcov::Dotfile.new
|
12
13
|
end
|
13
14
|
|
14
15
|
def report
|
@@ -27,13 +28,13 @@ module Swagcov
|
|
27
28
|
# https://github.com/rails/rails/tree/main/actionmailbox/app/controllers/action_mailbox
|
28
29
|
next if path.include?("/active_storage/") || path.include?("/action_mailbox/")
|
29
30
|
|
30
|
-
if ignore_path?(path)
|
31
|
+
if dotfile.ignore_path?(path)
|
31
32
|
@ignored += 1
|
32
33
|
@routes_ignored << { verb: route.verb, path: path, status: "ignored" }
|
33
34
|
next
|
34
35
|
end
|
35
36
|
|
36
|
-
next if only_path_mismatch?(path)
|
37
|
+
next if dotfile.only_path_mismatch?(path)
|
37
38
|
|
38
39
|
@total += 1
|
39
40
|
regex = Regexp.new("#{path.gsub(%r{:[^/]+}, '\\{[^/]+\\}')}(\\.[^/]+)?$")
|
@@ -56,41 +57,15 @@ module Swagcov
|
|
56
57
|
exit @total - @covered
|
57
58
|
end
|
58
59
|
|
59
|
-
def dotfile
|
60
|
-
@dotfile ||= YAML.load_file(Rails.root.join(".swagcov.yml"))
|
61
|
-
end
|
62
|
-
|
63
60
|
def docs_paths
|
64
|
-
@docs_paths ||= Dir.glob(dotfile
|
61
|
+
@docs_paths ||= Dir.glob(dotfile.doc_paths).reduce({}) do |acc, docspath|
|
65
62
|
acc.merge(YAML.load_file(docspath)["paths"])
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
69
66
|
private
|
70
67
|
|
71
|
-
|
72
|
-
ignored_regex&.match?(path)
|
73
|
-
end
|
74
|
-
|
75
|
-
def ignored_regex
|
76
|
-
@ignored_regex ||= path_config_regex(dotfile.dig("routes", "paths", "ignore"))
|
77
|
-
end
|
78
|
-
|
79
|
-
def only_path_mismatch? path
|
80
|
-
only_regex && !only_regex.match?(path)
|
81
|
-
end
|
82
|
-
|
83
|
-
def only_regex
|
84
|
-
@only_regex ||= path_config_regex(dotfile.dig("routes", "paths", "only"))
|
85
|
-
end
|
86
|
-
|
87
|
-
def path_config_regex path_config
|
88
|
-
return unless path_config
|
89
|
-
|
90
|
-
config = path_config.map { |path| path.first == "^" ? path : "#{path}$" }
|
91
|
-
|
92
|
-
/#{config.join('|')}/
|
93
|
-
end
|
68
|
+
attr_reader :dotfile
|
94
69
|
|
95
70
|
def routes_output routes, status_color
|
96
71
|
routes.each do |route|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Swagcov
|
4
|
+
class BadConfigurationError < RuntimeError
|
5
|
+
end
|
6
|
+
|
7
|
+
class Dotfile
|
8
|
+
def initialize
|
9
|
+
pathname = Rails.root.join(".swagcov.yml")
|
10
|
+
raise BadConfigurationError, "Missing .swagcov.yml" unless pathname.exist?
|
11
|
+
|
12
|
+
@dotfile = YAML.load_file(pathname)
|
13
|
+
raise BadConfigurationError, "Invalid .swagcov.yml" unless valid?
|
14
|
+
end
|
15
|
+
|
16
|
+
def ignore_path? path
|
17
|
+
ignored_regex&.match?(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def only_path_mismatch? path
|
21
|
+
only_regex && !only_regex.match?(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def doc_paths
|
25
|
+
dotfile.dig("docs", "paths")
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :dotfile
|
31
|
+
|
32
|
+
def ignored_regex
|
33
|
+
@ignored_regex ||= path_config_regex(dotfile.dig("routes", "paths", "ignore"))
|
34
|
+
end
|
35
|
+
|
36
|
+
def only_regex
|
37
|
+
@only_regex ||= path_config_regex(dotfile.dig("routes", "paths", "only"))
|
38
|
+
end
|
39
|
+
|
40
|
+
def path_config_regex path_config
|
41
|
+
return unless path_config
|
42
|
+
|
43
|
+
config = path_config.map { |path| path.first == "^" ? path : "^#{path}$" }
|
44
|
+
|
45
|
+
/#{config.join('|')}/
|
46
|
+
end
|
47
|
+
|
48
|
+
def valid?
|
49
|
+
dotfile && doc_paths
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/swagcov/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagcov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sarah Ridge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/swagcov.rb
|
80
80
|
- lib/swagcov/core_ext/string.rb
|
81
81
|
- lib/swagcov/coverage.rb
|
82
|
+
- lib/swagcov/dotfile.rb
|
82
83
|
- lib/swagcov/railtie.rb
|
83
84
|
- lib/swagcov/version.rb
|
84
85
|
- lib/tasks/swagcove.rake
|
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
106
|
- !ruby/object:Gem::Version
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
109
|
+
rubygems_version: 3.1.4
|
109
110
|
signing_key:
|
110
111
|
specification_version: 4
|
111
112
|
summary: Open API docs coverage for Rails Routes
|