oneshot_coverage 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d13259ff2122dd7ddb6bf748ce5157dd83838b0f5168586e8c68f1d885a1a1de
4
+ data.tar.gz: abf0ef7744a4526f1c341a2009c71589023c4b42e2dbc97c7a894454ba0ce38a
5
+ SHA512:
6
+ metadata.gz: 3bb1fdcf50628043fccdc2f6e0bebf0c827da063e5ba3e81bcb61757ae295ab1dc93fa05c0d0937999f515b61484ae897f59f3f093878343228c0e8f93629c1b
7
+ data.tar.gz: c84d545d172b17108f6539d224be37f6ba81e8059dab842847374123fa1f00bb81d518221d1a0f4768eeea6338e0664cf862262c51d64bdcd428f9d3133a46f3
data/.gitignore ADDED
@@ -0,0 +1,95 @@
1
+ # Created by https://www.gitignore.io/api/osx,ruby
2
+ # Edit at https://www.gitignore.io/?templates=osx,ruby
3
+
4
+ ### OSX ###
5
+ # General
6
+ .DS_Store
7
+ .AppleDouble
8
+ .LSOverride
9
+
10
+ # Icon must end with two \r
11
+ Icon
12
+
13
+ # Thumbnails
14
+ ._*
15
+
16
+ # Files that might appear in the root of a volume
17
+ .DocumentRevisions-V100
18
+ .fseventsd
19
+ .Spotlight-V100
20
+ .TemporaryItems
21
+ .Trashes
22
+ .VolumeIcon.icns
23
+ .com.apple.timemachine.donotpresent
24
+
25
+ # Directories potentially created on remote AFP share
26
+ .AppleDB
27
+ .AppleDesktop
28
+ Network Trash Folder
29
+ Temporary Items
30
+ .apdisk
31
+
32
+ ### Ruby ###
33
+ *.gem
34
+ *.rbc
35
+ /.config
36
+ /coverage/
37
+ /InstalledFiles
38
+ /pkg/
39
+ /spec/reports/
40
+ /spec/examples.txt
41
+ /test/tmp/
42
+ /test/version_tmp/
43
+ /tmp/
44
+
45
+ # Used by dotenv library to load environment variables.
46
+ # .env
47
+
48
+ # Ignore Byebug command history file.
49
+ .byebug_history
50
+
51
+ ## Specific to RubyMotion:
52
+ .dat*
53
+ .repl_history
54
+ build/
55
+ *.bridgesupport
56
+ build-iPhoneOS/
57
+ build-iPhoneSimulator/
58
+
59
+ ## Specific to RubyMotion (use of CocoaPods):
60
+ #
61
+ # We recommend against adding the Pods directory to your .gitignore. However
62
+ # you should judge for yourself, the pros and cons are mentioned at:
63
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
64
+ # vendor/Pods/
65
+
66
+ ## Documentation cache and generated files:
67
+ /.yardoc/
68
+ /_yardoc/
69
+ /doc/
70
+ /rdoc/
71
+
72
+ ## Environment normalization:
73
+ /.bundle/
74
+ /vendor/bundle
75
+ /lib/bundler/man/
76
+
77
+ # for a library or gem, you might want to ignore these files since the code is
78
+ # intended to run in multiple environments; otherwise, check them in:
79
+ # Gemfile.lock
80
+ # .ruby-version
81
+ # .ruby-gemset
82
+
83
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
84
+ .rvmrc
85
+
86
+ # End of https://www.gitignore.io/api/osx,ruby
87
+
88
+ /.bundle/
89
+ /.yardoc
90
+ /_yardoc/
91
+ /coverage/
92
+ /doc/
93
+ /pkg/
94
+ /spec/reports/
95
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sangyong-sim@cookpad.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in oneshot_coverage.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oneshot_coverage (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.17)
16
+ oneshot_coverage!
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Sangyong Sim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # OneshotCoverage
2
+
3
+ This gem is not very useful when you want to use oneshot coverage,
4
+ however, It could be good example to implement it by yourself.
5
+
6
+ This gem is to provide simple tools to use OneshotCoverage easier. It will log
7
+ files under the target path(usually, project base path).
8
+ In other word, This gem do not log codes under bundler gem path(if exist).
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'oneshot_coverage'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install oneshot_coverage
25
+
26
+ ## Usage
27
+
28
+ ### Configuration
29
+
30
+ ```ruby
31
+ OneshotCoverage.configure(
32
+ target_path: '/base/project/path',
33
+ logger: OneshotCoverage::Logger::NullLogger.new,
34
+ )
35
+ OneshotCoverage.start
36
+ ```
37
+
38
+ As default, OneshotCoverage supports 2 logger.
39
+
40
+ - OneshotCoverage::Logger::NullLogger (default)
41
+ - OneshotCoverage::Logger::StdoutLogger
42
+
43
+ Only required interface is `#post` instance method, so you could implement
44
+ by yourself easily.
45
+
46
+ ```ruby
47
+ class SampleFluentLogger
48
+ def initialize
49
+ @logger = Fluent::Logger::FluentLogger.new('tag_prefix')
50
+ end
51
+
52
+ def post(path:, md5_hash:, lineno:)
53
+ @logger.post(nil, path: path, md5_hash: md5_hash, lineno: lineno)
54
+ end
55
+ end
56
+ ```
57
+
58
+ ### Emit logs
59
+
60
+ #### With rack application
61
+
62
+ Please use `OneshotCoverage::Middleware`. This will emit logs per each request.
63
+
64
+ If you using Rails, below is enough.
65
+
66
+ ```
67
+ require 'oneshot_coverage/railtie'
68
+ ```
69
+
70
+ ### With job or batch application
71
+
72
+ If your job or batch are exit as soon as it finished(i.e. execute via rails runner),
73
+ then you don't need to do anything. `OneshotCoverage.start` will set trap
74
+ to emit via `at_exit`.
75
+ On the other hand, it's not, then you need to emit it manually
76
+ at proper timing(i.e. when batch finished)
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
81
+
82
+ ## Code of Conduct
83
+
84
+ Everyone interacting in the OneshotCoverage project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/riseshia/oneshot_coverage/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oneshot_coverage"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,95 @@
1
+ require "coverage"
2
+ require "digest/md5"
3
+
4
+ require "oneshot_coverage/logger/null_logger"
5
+ require "oneshot_coverage/railtie" if defined?(Rails)
6
+
7
+ module OneshotCoverage
8
+ class Middleware
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def call(env)
14
+ @app.call(env)
15
+ ensure
16
+ if Coverage.running?
17
+ OneshotCoverage.emit
18
+ end
19
+ end
20
+ end
21
+
22
+ class Reporter
23
+ def initialize(target_path:, logger:)
24
+ @target_path = target_path
25
+ @logger = logger
26
+ if defined?(Bundler)
27
+ @bundler_path = Bundler.bundle_path.to_s
28
+ end
29
+ end
30
+
31
+ def emit
32
+ Coverage.result(clear: true, stop: false).
33
+ select { |k, v| is_target?(k, v) }.
34
+ flat_map { |k, v| transform(k, v) }.
35
+ each { |row| @logger.post(row) }
36
+ end
37
+
38
+ def is_target?(filepath, value)
39
+ return false if value[:oneshot_lines].empty?
40
+ return false if !filepath.start_with?(@target_path)
41
+ return false if @bundle_path && !filepath.start_with?(@bundler_path)
42
+ true
43
+ end
44
+
45
+ def transform(filepath, value)
46
+ rel_path = filepath[@target_path.size..]
47
+ md5_hash =
48
+ if md5_hash_cache.key?(filepath)
49
+ md5_hash_cache[filepath]
50
+ else
51
+ md5_hash_cache[filepath] = Digest::MD5.file(filepath).hexdigest
52
+ end
53
+
54
+ value[:oneshot_lines].map do |line|
55
+ {
56
+ path: rel_path,
57
+ md5_hash: md5_hash,
58
+ lineno: line
59
+ }
60
+ end
61
+ end
62
+
63
+ def md5_hash_cache
64
+ @md5_hash_cache ||= {}
65
+ end
66
+ end
67
+
68
+ module_function
69
+
70
+ def start
71
+ Coverage.start(oneshot_lines: true)
72
+
73
+ # To handle execution with exit immediatly
74
+ at_exit do
75
+ OneshotCoverage.emit
76
+ end
77
+ end
78
+
79
+ def emit
80
+ @reporter&.emit
81
+ end
82
+
83
+ def configure(target_path:, logger: OneshotCoverage::Logger::NullLogger.new)
84
+ target_path_by_pathname =
85
+ if target_path.is_a? Pathname
86
+ target_path
87
+ else
88
+ Pathname.new(target_path)
89
+ end
90
+ @reporter = OneshotCoverage::Reporter.new(
91
+ target_path: target_path_by_pathname.cleanpath.to_s + "/",
92
+ logger: logger,
93
+ )
94
+ end
95
+ end
@@ -0,0 +1,9 @@
1
+ module OneshotCoverage
2
+ module Logger
3
+ class NullLogger
4
+ def post(_row)
5
+ # Do nothing
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module OneshotCoverage
2
+ module Logger
3
+ class StdoutLogger
4
+ def post(path:, md5_hash:, lineno:)
5
+ $stdout.puts(
6
+ "[OneshotCoverage] logged path: #{path}, md5_hash: #{md5_hash}, lineno: #{lineno}"
7
+ )
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ unless defined? Rails::Railtie
2
+ raise "You need to install and require Rails to use this integration"
3
+ end
4
+
5
+ module OneshotCoverage
6
+ class Railtie < Rails::Railtie
7
+ initializer 'oneshot_coverage.configure' do |app|
8
+ app.middleware.use OneshotCoverage::Middleware
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module OneshotCoverage
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "oneshot_coverage/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oneshot_coverage"
8
+ spec.version = OneshotCoverage::VERSION
9
+ spec.authors = ["Shia"]
10
+ spec.email = ["rise.shia@gmail.com"]
11
+
12
+ spec.summary = %q{Simple toolbox for oneshot coverage}
13
+ spec.description = %q{OneshotCoverage will help you to measure oneshot coverage on production}
14
+ spec.homepage = "https://github.com/riseshia/oneshot_coverage"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/riseshia/oneshot_coverage"
22
+ spec.metadata["changelog_uri"] = "https://github.com/riseshia/oneshot_coverage"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ # spec.bindir = "exe"
34
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.required_ruby_version = '>= 2.6.1'
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oneshot_coverage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: OneshotCoverage will help you to measure oneshot coverage on production
42
+ email:
43
+ - rise.shia@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - lib/oneshot_coverage.rb
58
+ - lib/oneshot_coverage/logger/null_logger.rb
59
+ - lib/oneshot_coverage/logger/stdout_logger.rb
60
+ - lib/oneshot_coverage/railtie.rb
61
+ - lib/oneshot_coverage/version.rb
62
+ - oneshot_coverage.gemspec
63
+ homepage: https://github.com/riseshia/oneshot_coverage
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ homepage_uri: https://github.com/riseshia/oneshot_coverage
68
+ source_code_uri: https://github.com/riseshia/oneshot_coverage
69
+ changelog_uri: https://github.com/riseshia/oneshot_coverage
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.6.1
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.0.1
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Simple toolbox for oneshot coverage
89
+ test_files: []