coverage-badge 0.1.0 → 0.1.1

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: f8b08d8f0f96e80b8f47c0feaec404fce5190008eb953755ce3826ae6d51de88
4
- data.tar.gz: '0319b57380664fac7f426d12d63d46ba929c7b414975284cbe9224937827c6ec'
3
+ metadata.gz: 41b6fd5fc9fb5888a6d87619db6d1c789e9b927006a0b721322a982487fb0837
4
+ data.tar.gz: 26ca2e7f32290e215e87e2c823270ec12e61d150c7722bb11ef03394c5f9a230
5
5
  SHA512:
6
- metadata.gz: f0f62e38667dc0b648a866d1aef9550ebc8d2c6e6915e766b6961600ff1c6c9a665fb820a14526161a96384c79472aeea45931f7a9e152f517de17c16fcdd343
7
- data.tar.gz: 67bb5b18535dd05136366d21440ae55cb69091f84437980b8cc209d3751967ca72aa90e51e4031592d66901c552d8344c6776385c792d3a5c4922016db5596e9
6
+ metadata.gz: 76f9666be30f157ef781da9efe7c4ca7fef969c91e344fe6931cc1931f4c16494aa6513551f85d0e66edbe6a3b773e35759bab1cd2e93d7dff242a28b108c9cb
7
+ data.tar.gz: bae69e44f88ae2acb63b3f128eeec22762fe6387de3696fe204bae229fa145641a5d49ae8a1642847df141264627e58ad8657ab04d0408794f5324f0ef910bfc
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'coverage/badge/version'
4
+ require 'coverage/badge/formatter'
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coverage
4
+ module Badge
5
+ class Formatter
6
+ DEFAULT_COLOR = '#e05d44'
7
+
8
+ COLORS = {
9
+ (91..100) => '#4c1',
10
+ (76..90) => '#97CA00',
11
+ (61..75) => '#a4a61d',
12
+ (41..60) => '#dfb317',
13
+ (1..40) => '#fe7d37'
14
+ }.freeze
15
+
16
+ def format(result)
17
+ coverage = result&.source_files&.covered_percent&.round(0)
18
+ raise ArgumentError, 'Please configure Simplecov' unless coverage
19
+
20
+ badge = template(coverage)
21
+ export_to_file('/coverage/badge.svg', badge)
22
+ end
23
+
24
+ private
25
+
26
+ def template(coverage)
27
+ template = File.read(resource_dir + '/template/flat.svg')
28
+
29
+ template.gsub!('{{ total }}', coverage.to_s)
30
+ template.gsub!('{{ color }}', color(coverage))
31
+
32
+ template
33
+ end
34
+
35
+ def export_to_file(path, content)
36
+ fh = File.open(current_dir + path, 'w')
37
+ fh.write(content)
38
+ fh.close
39
+ end
40
+
41
+ def color(coverage)
42
+ COLORS.each do |range, value|
43
+ return value if range.member?(coverage)
44
+ end
45
+
46
+ DEFAULT_COLOR
47
+ end
48
+
49
+ def resource_dir
50
+ File.expand_path(__dir__)
51
+ end
52
+
53
+ def current_dir
54
+ Dir.pwd
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="99" height="20">
3
+ <linearGradient id="b" x2="0" y2="100%">
4
+ <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
5
+ <stop offset="1" stop-opacity=".1"/>
6
+ </linearGradient>
7
+ <mask id="a">
8
+ <rect width="99" height="20" rx="3" fill="#fff"/>
9
+ </mask>
10
+ <g mask="url(#a)">
11
+ <path fill="#555" d="M0 0h63v20H0z"/>
12
+ <path fill="{{ color }}" d="M63 0h36v20H63z"/>
13
+ <path fill="url(#b)" d="M0 0h99v20H0z"/>
14
+ </g>
15
+ <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
16
+ <text x="31.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
17
+ <text x="31.5" y="14">coverage</text>
18
+ <text x="80" y="15" fill="#010101" fill-opacity=".3">{{ total }}%</text>
19
+ <text x="80" y="14">{{ total }}%</text>
20
+ </g>
21
+ </svg>
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coverage
4
+ module Badge
5
+ VERSION = '0.1.1'
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverage-badge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Orsoev
@@ -101,19 +101,9 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - ".gitignore"
105
- - ".rspec"
106
- - ".rubocop.yml"
107
- - ".ruby-version"
108
- - Gemfile
109
- - Gemfile.lock
110
- - Makefile
111
- - README.md
112
- - Rakefile
113
- - bin/console
114
- - bin/setup
115
- - coverage-badge.gemspec
116
104
  - lib/coverage/badge.rb
105
+ - lib/coverage/badge/formatter.rb
106
+ - lib/coverage/badge/template/flat.svg
117
107
  - lib/coverage/badge/version.rb
118
108
  homepage: https://rubygems.org/gems/coverage-badge
119
109
  licenses: []
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- .bundle/
2
- .yardoc
3
- _yardoc/
4
- doc/
5
- pkg/
6
- spec/reports/
7
- tmp/
8
-
9
- coverage/
10
- coverage/.rspec_status
11
-
12
- *.gem
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,2 +0,0 @@
1
- Style/Documentation:
2
- Enabled: false
@@ -1 +0,0 @@
1
- 2.6.3
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
- gemspec
@@ -1,60 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- coverage-badge (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.0)
10
- diff-lcs (1.3)
11
- docile (1.3.2)
12
- jaro_winkler (1.5.3)
13
- json (2.2.0)
14
- parallel (1.17.0)
15
- parser (2.6.3.0)
16
- ast (~> 2.4.0)
17
- rainbow (3.0.0)
18
- rake (10.5.0)
19
- rspec (3.8.0)
20
- rspec-core (~> 3.8.0)
21
- rspec-expectations (~> 3.8.0)
22
- rspec-mocks (~> 3.8.0)
23
- rspec-core (3.8.0)
24
- rspec-support (~> 3.8.0)
25
- rspec-expectations (3.8.3)
26
- diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.8.0)
28
- rspec-mocks (3.8.0)
29
- diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.8.0)
31
- rspec-support (3.8.0)
32
- rubocop (0.74.0)
33
- jaro_winkler (~> 1.5.1)
34
- parallel (~> 1.10)
35
- parser (>= 2.6)
36
- rainbow (>= 2.2.2, < 4.0)
37
- ruby-progressbar (~> 1.7)
38
- unicode-display_width (>= 1.4.0, < 1.7)
39
- ruby-progressbar (1.10.1)
40
- simplecov (0.17.0)
41
- docile (~> 1.1)
42
- json (>= 1.8, < 3)
43
- simplecov-html (~> 0.10.0)
44
- simplecov-html (0.10.2)
45
- unicode-display_width (1.6.0)
46
-
47
- PLATFORMS
48
- ruby
49
-
50
- DEPENDENCIES
51
- bundler (~> 1.17)
52
- coverage-badge!
53
- rake (~> 10.0)
54
- rspec (~> 3.8.0)
55
- rspec-core (~> 3.8.0)
56
- rubocop (~> 0.74.0)
57
- simplecov (~> 0.17.0)
58
-
59
- BUNDLED WITH
60
- 1.17.3
data/Makefile DELETED
@@ -1,5 +0,0 @@
1
- build:
2
- gem build coverage-badge.gemspec
3
-
4
- install: build
5
- gem install ./coverage-badge-0.1.0.gem
data/README.md DELETED
@@ -1,48 +0,0 @@
1
- # Coverage::Badge
2
-
3
- Generate a SVG badge for code coverage in your project
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'coverage-badge', '~> 0.1.0 '
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install coverage-badge
20
-
21
- ## Usage
22
-
23
- ```ruby
24
- if ENV['CI'] == 'true'
25
- require 'simplecov'
26
-
27
- SimpleCov.start 'rails' do
28
- require 'coverage-badge'
29
-
30
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
31
- [
32
- SimpleCov::Formatter::HTMLFormatter,
33
- Coverage::Badge::Formatter
34
- ]
35
- )
36
- end
37
- end
38
- ```
39
-
40
- ## Development
41
-
42
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
-
44
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
-
46
- ## Contributing
47
-
48
- Bug reports and pull requests are welcome on GitHub at https://github.com/andreyors/coverage-badge.
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'coverage/badge'
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require 'irb'
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'coverage/badge/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = 'coverage-badge'
9
- spec.version = Coverage::Badge::VERSION
10
- spec.authors = ['Andrey Orsoev']
11
- spec.email = ['andrey.orsoev@gmail.com']
12
-
13
- spec.summary = 'Generate a SVG badge with coverage data'
14
- spec.description = 'Provide a coverage information for your codebase'
15
- spec.homepage = 'https://rubygems.org/gems/coverage-badge'
16
-
17
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
19
- end
20
- spec.require_paths = ['lib']
21
-
22
- spec.add_development_dependency 'bundler', '~> 1.17'
23
- spec.add_development_dependency 'rake', '~> 10.0'
24
- spec.add_development_dependency 'rspec', '~> 3.8.0'
25
- spec.add_development_dependency 'rspec-core', '~> 3.8.0'
26
- spec.add_development_dependency 'rubocop', '~> 0.74.0'
27
- spec.add_development_dependency 'simplecov', '~> 0.17.0'
28
- end