swagcov 0.1.0 → 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: c84f31d41e49c7d90290cbdc863d512896100660cf777b66fc2a41837dafadf5
4
- data.tar.gz: 87af9e2410c54d994f4c6d2832b7a905216aba3a4d25a27691ec49f78c8f5715
3
+ metadata.gz: 83f05163f3408b08db9f9810e5eb82a4285877d9e7b7af60a83e44386eab5c04
4
+ data.tar.gz: 76b1bf03e51bc42e516f5b77536d1ae38685dd642823094a0ac8e67fa8c67ac3
5
5
  SHA512:
6
- metadata.gz: 28db77ab060836b1b98a4e38de339b96f613de5d954f67050840f722a0d6b484c2d12da003479999ebcee42d506963826a776a28faaa85bb9d437b4a44e178cb
7
- data.tar.gz: 382179ddd4f08e04823f0c9bf2f2f8925ba1929bc12d6baadb0882de172684a8361d95fddb55b66ab5669e76cc3d6062bac9cf3f5c1a0d4149273fa27d35b6ab
6
+ metadata.gz: 82610986597a8a832173354fb452a4d63c7c0a22a342ec10fd2ac6bcb3eef845d306c6d37225ac837b22febcb12a0ba093167b71d3acc94aaabb8394789b77a7
7
+ data.tar.gz: a1cdf7691af9fce07dfc50711a748bcbfe903ef0f5f5b94e3d1b3d7fd605ac125de92db23121a8ccdb8622494bfba431f7f3710e55f6392a20160e5c2bfd4e4f
data/README.md CHANGED
@@ -72,10 +72,22 @@ gem "swagcov", path: "../swagcov"
72
72
  bundle
73
73
  ```
74
74
 
75
+ ## Publish (internal)
76
+ > Note: Publishing a new version of this gem is only meant for maintainers.
77
+ - Ensure you have access to publish on [rubygems](https://rubygems.org/gems/swagcov).
78
+ - Update [CHANGELOG](https://github.com/smridge/swagcov/blob/main/CHANGELOG.md).
79
+ - Update [`VERSION`](https://github.com/smridge/swagcov/blob/main/lib/swagcov/version.rb).
80
+ - Commit changes to `main` branch locally.
81
+ - Run: `rake release`
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).
83
+
75
84
  ## TODO
76
85
  - Add specs
77
86
  - Test against different rails versions
87
+ - Create Sandbox Apps for Rails 5 & 6
78
88
  - Add autogeneration of ignore paths
89
+ - Add `CONTRIBUTING.md`
90
+ - Add GitHub Actions for specs/linting
79
91
 
80
92
  ## Credit
81
93
  To [@lonelyelk](https://github.com/lonelyelk) for initial development!
data/lib/swagcov.rb CHANGED
@@ -4,8 +4,11 @@ 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
 
11
+ require "swagcov/core_ext/string"
12
+
10
13
  module Swagcov
11
14
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ COLORS = {
5
+ red: 31,
6
+ green: 32,
7
+ yellow: 33,
8
+ blue: 34
9
+ }.freeze
10
+
11
+ # returns bold colors
12
+ COLORS.each_pair do |color, value|
13
+ define_method(color) do
14
+ "\e[1;#{value}m#{self}\e[0m"
15
+ end
16
+ end
17
+ end
@@ -9,19 +9,32 @@ 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
15
16
  Rails.application.routes.routes.each do |route|
17
+ # https://github.com/rails/rails/blob/48f3c3e201b57a4832314b2c957a3b303e89bfea/actionpack/lib/action_dispatch/routing/inspector.rb#L105-L107
18
+ # Skips route paths like ["/rails/info/properties", "/rails/info", "/rails/mailers"]
19
+ next if route.internal
20
+
21
+ # Skips routes like "/sidekiq"
22
+ next unless route.verb.present?
23
+
16
24
  path = route.path.spec.to_s.sub(/\(\.:format\)$/, "")
17
25
 
18
- if ignore_path?(path)
26
+ # Exclude routes that are part of the rails gem that you would not write documentation for
27
+ # https://github.com/rails/rails/tree/main/activestorage/app/controllers/active_storage
28
+ # https://github.com/rails/rails/tree/main/actionmailbox/app/controllers/action_mailbox
29
+ next if path.include?("/active_storage/") || path.include?("/action_mailbox/")
30
+
31
+ if dotfile.ignore_path?(path)
19
32
  @ignored += 1
20
33
  @routes_ignored << { verb: route.verb, path: path, status: "ignored" }
21
34
  next
22
35
  end
23
36
 
24
- next if only_path_mismatch?(path)
37
+ next if dotfile.only_path_mismatch?(path)
25
38
 
26
39
  @total += 1
27
40
  regex = Regexp.new("#{path.gsub(%r{:[^/]+}, '\\{[^/]+\\}')}(\\.[^/]+)?$")
@@ -41,44 +54,18 @@ module Swagcov
41
54
 
42
55
  final_output
43
56
 
44
- (@total - @covered).zero?
45
- end
46
-
47
- def dotfile
48
- @dotfile ||= YAML.load_file(Rails.root.join(".swagcov.yml"))
57
+ exit @total - @covered
49
58
  end
50
59
 
51
60
  def docs_paths
52
- @docs_paths ||= Dir.glob(dotfile["docs"]["paths"]).reduce({}) do |acc, docspath|
61
+ @docs_paths ||= Dir.glob(dotfile.doc_paths).reduce({}) do |acc, docspath|
53
62
  acc.merge(YAML.load_file(docspath)["paths"])
54
63
  end
55
64
  end
56
65
 
57
66
  private
58
67
 
59
- def ignore_path? path
60
- ignored_regex&.match?(path)
61
- end
62
-
63
- def ignored_regex
64
- @ignored_regex ||= path_config_regex(dotfile.dig("routes", "paths", "ignore"))
65
- end
66
-
67
- def only_path_mismatch? path
68
- only_regex && !only_regex.match?(path)
69
- end
70
-
71
- def only_regex
72
- @only_regex ||= path_config_regex(dotfile.dig("routes", "paths", "only"))
73
- end
74
-
75
- def path_config_regex path_config
76
- return unless path_config
77
-
78
- config = path_config.map { |path| path.first == "^" ? path : "#{path}$" }
79
-
80
- /#{config.join('|')}/
81
- end
68
+ attr_reader :dotfile
82
69
 
83
70
  def routes_output routes, status_color
84
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.1.0"
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.1.0
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-02-24 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
@@ -77,7 +77,9 @@ files:
77
77
  - README.md
78
78
  - Rakefile
79
79
  - lib/swagcov.rb
80
+ - lib/swagcov/core_ext/string.rb
80
81
  - lib/swagcov/coverage.rb
82
+ - lib/swagcov/dotfile.rb
81
83
  - lib/swagcov/railtie.rb
82
84
  - lib/swagcov/version.rb
83
85
  - lib/tasks/swagcove.rake
@@ -104,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
106
  - !ruby/object:Gem::Version
105
107
  version: '0'
106
108
  requirements: []
107
- rubygems_version: 3.2.3
109
+ rubygems_version: 3.1.4
108
110
  signing_key:
109
111
  specification_version: 4
110
112
  summary: Open API docs coverage for Rails Routes