rake-file-content 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: 5c45b6a172da6ba79adcdaec29c3cdbb36699232f1909ba50c39b40aadd0252a
4
+ data.tar.gz: 07d124fff743d8efda802d268ab415f6f84c014cb8de276dedefdcb4fc372748
5
+ SHA512:
6
+ metadata.gz: 108dad1e1e320678815267ffed95e05176b5afdb753159e80b4e2b6de76fc69191e7f423a45f0d11eafe2000752f658759beb72c1d02cc7a4cc81c0f199d0808
7
+ data.tar.gz: 67143b41f0fbe436122fc7f0268fb1d78658f45b0a6967e80c6ec2b7105549fb82dbbf4f4bcc697b594ba09826370fd34993908dd693928531112726945ebb20
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ https://twitter.com/mattie.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 13.0"
8
+ gem "minitest", "~> 5.0"
9
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rake-file-content (0.1.0)
5
+ rake
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ minitest (5.15.0)
12
+ parallel (1.22.1)
13
+ parser (3.1.2.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.3.0)
18
+ rexml (3.2.5)
19
+ rubocop (1.27.0)
20
+ parallel (~> 1.10)
21
+ parser (>= 3.1.0.0)
22
+ rainbow (>= 2.2.2, < 4.0)
23
+ regexp_parser (>= 1.8, < 3.0)
24
+ rexml
25
+ rubocop-ast (>= 1.16.0, < 2.0)
26
+ ruby-progressbar (~> 1.7)
27
+ unicode-display_width (>= 1.4.0, < 3.0)
28
+ rubocop-ast (1.17.0)
29
+ parser (>= 3.1.1.0)
30
+ ruby-progressbar (1.11.0)
31
+ unicode-display_width (2.1.0)
32
+
33
+ PLATFORMS
34
+ arm64-darwin-21
35
+
36
+ DEPENDENCIES
37
+ minitest (~> 5.0)
38
+ rake (~> 13.0)
39
+ rake-file-content!
40
+ rubocop (~> 1.7)
41
+
42
+ BUNDLED WITH
43
+ 2.2.22
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022, Matt Massicotte
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # rake-file-content
2
+
3
+ By default, rake's `file` tasks determine dependencies and requirements by file modification date. This gem makes it possible to compute requirements by file contents. It's a little slower in the best case, but avoids many correctness pitfalls that a date-only implementation suffers from.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rake-file-content'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rake-file-content
20
+
21
+ ## Usage
22
+
23
+ You can simply replace the `file` Rake DSL method with `file_content`. It behaves the same, but will output a a `.content_hash` file with the same name next to the output. This file will be used to determine if the task is needed in the future. It will be triggered if the hashes change.
24
+
25
+ A potential gotcha with standard rake `file` is when you remove dependencies. At this point, your file might not be rebuilt, but since `file` has no memory between rake invocations, it will not be invoked. A `file_content` task will.
26
+
27
+ Internally, `file_content` will work with any rake task that responds to `content_hash`. This gem adds this to `file` tasks, and the [rake-remote-file](https://github.com/mattmassicotte/rake-remote-file) does it too, just in case that's of interest.
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mattmassicotte/rake-file-content. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rake-file-content/blob/main/CODE_OF_CONDUCT.md).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the rake-file-content project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rake-file-content/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rake/file/content"
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 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,11 @@
1
+ require 'digest/md5'
2
+
3
+ module Rake
4
+ class FileTask
5
+ def content_hash
6
+ Digest::MD5.hexdigest(File.read(name))
7
+ rescue
8
+ nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ module RakeContentFile
2
+ class DependencyList
3
+ attr_accessor :list
4
+
5
+ def initialize
6
+ @list = []
7
+ end
8
+
9
+ def ==(other)
10
+ sorted_list == other.sorted_list
11
+ end
12
+
13
+ def sorted_list
14
+ list.sort_by(&:first)
15
+ end
16
+
17
+ def add(name, hash)
18
+ list << [name, hash]
19
+ end
20
+
21
+ def serialize
22
+ data = ""
23
+
24
+ sorted_list.each do |dep_name, hash|
25
+ data << "#{dep_name}: #{hash}\n"
26
+ end
27
+
28
+ data
29
+ end
30
+
31
+ def self.deserialize(data)
32
+ deps = self.new
33
+
34
+ data.lines do |line|
35
+ deps.list << line.chomp.split(": ")
36
+ end
37
+
38
+ deps
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ require 'rake'
2
+
3
+ module RakeFileContent
4
+ module DSL
5
+ include Rake::DSL
6
+
7
+ def file_content(*args, &block)
8
+ RakeContentFile::Task.define_task(*args, &block)
9
+ end
10
+
11
+ end
12
+ end
13
+
14
+ extend RakeFileContent::DSL
@@ -0,0 +1,67 @@
1
+ require_relative "dependency_list"
2
+
3
+ module RakeContentFile
4
+ class Task < Rake::FileTask
5
+ attr_accessor :source_file
6
+
7
+ def initialize(task_name, app)
8
+ super(task_name, app)
9
+ end
10
+
11
+ def needed?
12
+ dependent_contents_changed?
13
+ end
14
+
15
+ def execute(args=nil)
16
+ super
17
+
18
+ File.open(cache_file, "w") do |f|
19
+ f << dep_list.serialize
20
+ end
21
+ end
22
+
23
+ def dependent_contents_changed?
24
+ return true if cached_dep_list.nil?
25
+
26
+ dep_list != cached_dep_list
27
+ end
28
+
29
+ def cache_file
30
+ name + ".content_hash"
31
+ end
32
+
33
+ private
34
+ def dep_list
35
+ @dep_list ||= make_dep_list
36
+ end
37
+
38
+ def cached_dep_list
39
+ @cached_dep_list ||= read_cached_dep_list
40
+ end
41
+
42
+ def read_cached_dep_list
43
+ return nil unless File.exist?(cache_file)
44
+
45
+ data = File.open(cache_file).read
46
+
47
+ DependencyList.deserialize(data)
48
+ end
49
+
50
+ def make_dep_list
51
+ list = DependencyList.new
52
+
53
+ dependent_content_tasks.each do |task|
54
+ list.add(task.name, task.content_hash)
55
+ end
56
+
57
+ list
58
+ end
59
+
60
+ def dependent_content_tasks
61
+ all_prerequisite_tasks.filter do |prereq|
62
+ prereq_task = application[prereq, @scope]
63
+ prereq_task.respond_to?(:content_hash)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RakeFileContent
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake-file-content/version'
4
+ require 'rake-file-content/dsl'
5
+ require 'rake-file-content/task'
6
+ require 'rake-file-content/content_hash'
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rake-file-content/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rake-file-content"
7
+ spec.version = RakeFileContent::VERSION
8
+ spec.authors = ["Matthew Massicotte"]
9
+
10
+ spec.summary = "Rake DSL extensions for managing file dependencies by content"
11
+ spec.description = spec.summary
12
+ spec.homepage = "https://github.com/mattmassicotte/rake-file-content"
13
+ spec.required_ruby_version = ">= 2.4.0"
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency "rake"
30
+
31
+ spec.add_development_dependency "minitest"
32
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-file-content
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Massicotte
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Rake DSL extensions for managing file dependencies by content
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CODE_OF_CONDUCT.md
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/rake-file-content.rb
56
+ - lib/rake-file-content/content_hash.rb
57
+ - lib/rake-file-content/dependency_list.rb
58
+ - lib/rake-file-content/dsl.rb
59
+ - lib/rake-file-content/task.rb
60
+ - lib/rake-file-content/version.rb
61
+ - rake-file-content.gemspec
62
+ homepage: https://github.com/mattmassicotte/rake-file-content
63
+ licenses: []
64
+ metadata:
65
+ allowed_push_host: https://rubygems.org
66
+ homepage_uri: https://github.com/mattmassicotte/rake-file-content
67
+ source_code_uri: https://github.com/mattmassicotte/rake-file-content
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.4.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.2.22
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Rake DSL extensions for managing file dependencies by content
87
+ test_files: []