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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2973e06bae3594a017e460bb2729a55af6eb7a9c577d30e2eb7fdbc38ec2a4e
4
- data.tar.gz: caf357b0caf1631d0d05cd33cbe72d89292be15435f7446c185b9310b458e7a5
3
+ metadata.gz: 83f05163f3408b08db9f9810e5eb82a4285877d9e7b7af60a83e44386eab5c04
4
+ data.tar.gz: 76b1bf03e51bc42e516f5b77536d1ae38685dd642823094a0ac8e67fa8c67ac3
5
5
  SHA512:
6
- metadata.gz: b6bbf2610deff567d6e53af5aa5e6a6a698f8a8ddb41e950cfaa8b43671a4fa691e0f1efc026390b9ee0325be26122aadb6f0858c97d34d1ff6e0fc41661b6ed
7
- data.tar.gz: 27b8c790681655912e0cf05622446b5782adc4b6b2441d745f0cf02fcc8b288a8cbeab856eb3285adc75d5a4a8750679d83b5898d76a03a4d641802b76c2b5f4
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
@@ -4,6 +4,7 @@ require "swagcov/version"
4
4
 
5
5
  if defined?(Rails)
6
6
  require "swagcov/railtie"
7
+ require "swagcov/dotfile"
7
8
  require "swagcov/coverage"
8
9
  end
9
10
 
@@ -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["docs"]["paths"]).reduce({}) do |acc, docspath|
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
- def ignore_path? path
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Swagcov
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
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.3
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-23 00:00:00.000000000 Z
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.2.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