sane_patch 0.1.0 → 0.2.0
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 +4 -4
- data/.travis.yml +13 -1
- data/CHANGELOG.md +19 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +60 -39
- data/lib/sane_patch.rb +11 -6
- data/lib/sane_patch/version.rb +1 -1
- data/logo.png +0 -0
- data/sane_patch.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd06cfb6785effd7bfbc07c1c212ef2b43d6ca480a46b9a180d06800f2790740
|
4
|
+
data.tar.gz: '05435385730e1d6da0d6215f614e1c2a871ae2e286aeb53b2ea74af1d04ebb69'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35d37b2964aeb895dd90b92c2b414f23c127363f83e8f2b3b9a06d9dd33b96f26450fab623cd7f63b0f2be9f45ce8ff5679277b3412767a551a9b7a9361b9fe2
|
7
|
+
data.tar.gz: '08754a0f5d071c5c4fe9bbcc6764beedc6f2014b78da60b91abcca2849228ff25ec0743d4bba0be328e7448f97406881552bc3178eaf5abfcd483ace07151fa4'
|
data/.travis.yml
CHANGED
@@ -4,4 +4,16 @@ language: ruby
|
|
4
4
|
cache: bundler
|
5
5
|
rvm:
|
6
6
|
- 2.6.3
|
7
|
-
|
7
|
+
- ruby-head
|
8
|
+
|
9
|
+
matrix:
|
10
|
+
fast_finish: true
|
11
|
+
allow_failures:
|
12
|
+
- rvm: ruby-head
|
13
|
+
|
14
|
+
before_install:
|
15
|
+
- gem update --system
|
16
|
+
- gem install bundler -v 2.0.1
|
17
|
+
|
18
|
+
script:
|
19
|
+
- bundle exec rspec
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.2.0] - 2019-06-25
|
10
|
+
### Added
|
11
|
+
- Added test-suite covering existing functionality by [@PikachuEXE](https://github.com/PikachuEXE)
|
12
|
+
- Added the ability to specify more complex version constraints, we now support all constraints supported by [`RubyGems`](http://docs.seattlerb.org/rubygems/Gem/Requirement.html) thanks to the work of [@PikachuEXE](https://github.com/PikachuEXE) and [@jrochkind](https://github.com/jrochkind).
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- Fix Typo in code example used in README.
|
16
|
+
- Fix Typo in `gemspec` description.
|
17
|
+
- Use custom `SanePatch::Errors::GemAbsent` instead of `ArgumentError` when a unloaded gem is patched. `SanePatch::Errors::GemAbsent` inherits `ArgumentError`.
|
18
|
+
- Use custom `SanePatch::Errors::IncompatibleVersion` instead of `RuntimeError` when a loaded gem does not meet the requirements of a patch. For backwards compatibility reasons `SanePatch::Errors::IncompatibleVersion` inherits `RuntimeError`.
|
19
|
+
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at joel
|
58
|
+
reported by contacting the project team at hello@joel.am. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
<img src="https://raw.githubusercontent.com/Jcambass/sane_patch/master/logo.png" width="100" height="100">
|
2
|
+
|
1
3
|
# SanePatch
|
2
4
|
|
3
5
|
SanePatch is a simple and non intrusive helper that aims to make monkey patching a little bit safer.
|
@@ -32,74 +34,93 @@ The usage of SanePatch is straight forward:
|
|
32
34
|
|
33
35
|
```ruby
|
34
36
|
SanePatch.patch('<gem name>', '<current gem version>') do
|
35
|
-
|
36
|
-
|
37
|
+
# Apply your patches here the same way as usual.
|
38
|
+
end
|
37
39
|
```
|
38
40
|
|
39
41
|
A more specific example:
|
40
42
|
|
41
43
|
```ruby
|
44
|
+
Greeter.greet # => 'Hello'
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
def greet
|
48
|
-
"#{super} Folks"
|
49
|
-
end
|
46
|
+
# Let's patch the `Greeter.greet` method to output 'Hello Folks'
|
47
|
+
module GreeterPatch
|
48
|
+
def greet
|
49
|
+
"#{super} Folks"
|
50
50
|
end
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
# We currently have version 1.1.0 of the greeter gem
|
54
|
+
SanePatch.patch('greeter', '1.1.0') do
|
55
|
+
Greeter.prepend(GreeterPatch)
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
+
Greeter.greet # => 'Hello Folks'
|
58
59
|
```
|
59
60
|
|
60
61
|
If somebody updates the gem version the patch will raise as soon as its code path is executed:
|
61
62
|
```
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
SanePatch::Errors::IncompatibleVersion:
|
64
|
+
It looks like the greeter gem was upgraded.
|
65
|
+
There are patches in place that need to be verified.
|
66
|
+
Make sure that the patch at initializers/greeter_patch.rb:8 is still needed and working.
|
65
67
|
```
|
66
68
|
|
69
|
+
### Complex version constraints
|
70
|
+
|
71
|
+
SanePatch supports all [version constraints](http://docs.seattlerb.org/rubygems/Gem/Requirement.html) you know and love from RubyGems.
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
SanePatch.patch('greeter', '~> 1.1.0') { # your patch }
|
75
|
+
SanePatch.patch('greeter', '> 1.1.0') { # your patch }
|
76
|
+
SanePatch.patch('greeter', '< 1.1.0') { # your patch }
|
77
|
+
```
|
78
|
+
|
79
|
+
It even supports version ranges based on multiple constraints:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
SanePatch.patch('greeter', '> 1.0.0', '< 1.1.0') { # your patch }
|
83
|
+
```
|
84
|
+
|
85
|
+
This is especially useful if you patch a bug where you know the affected gem versions.
|
86
|
+
|
67
87
|
### Providing additional information
|
68
88
|
|
69
89
|
If you patch a known bug in a gem it might be useful to provide additional information why the patch is needed and when it can be removed.
|
70
90
|
|
71
91
|
```ruby
|
72
|
-
|
92
|
+
Greeter.silence # => nil
|
73
93
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
94
|
+
module GreeterPatch
|
95
|
+
def silence
|
96
|
+
''
|
78
97
|
end
|
98
|
+
end
|
79
99
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
100
|
+
details = <<-MSG
|
101
|
+
The `silence` method should output an empty string rather than nil.
|
102
|
+
This is a known issue and will be fixed in the next release.
|
103
|
+
See: https://github.com/Jcambass/greeter/issues/45
|
104
|
+
MSG
|
85
105
|
|
86
|
-
|
87
|
-
|
88
|
-
|
106
|
+
SanePatch.patch('greeter', '1.1.0', details: details) do
|
107
|
+
Greeter.prepend(GreeterPatch)
|
108
|
+
end
|
89
109
|
|
90
|
-
|
110
|
+
Greeter.silence # => ''
|
91
111
|
```
|
92
112
|
|
93
113
|
The additionally provided details will also show up in the exception message.
|
94
114
|
|
95
115
|
```
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
116
|
+
SanePatch::Errors::IncompatibleVersion:
|
117
|
+
It looks like the greeter gem was upgraded.
|
118
|
+
There are patches in place that need to be verified.
|
119
|
+
Make sure that the patch at initializers/greeter_patch.rb:8 is still needed and working.
|
120
|
+
Details:
|
121
|
+
The `silence` method should output an empty string rather than nil.
|
122
|
+
This is a known issue and will be fixed in the next release.
|
123
|
+
See: https://github.com/Jcambass/greeter/issues/45
|
103
124
|
```
|
104
125
|
|
105
126
|
## Contributing
|
@@ -112,4 +133,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
112
133
|
|
113
134
|
## Code of Conduct
|
114
135
|
|
115
|
-
Everyone interacting in the SanePatch project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
136
|
+
Everyone interacting in the SanePatch project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Jcambass/sane_patch/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/sane_patch.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
require "sane_patch/version"
|
2
2
|
|
3
3
|
module SanePatch
|
4
|
-
|
4
|
+
module Errors
|
5
|
+
GemAbsent = Class.new(ArgumentError)
|
6
|
+
IncompatibleVersion = Class.new(RuntimeError)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.patch(gem_name, *requirements, details: nil)
|
5
10
|
gem_spec = Gem.loaded_specs[gem_name]
|
6
|
-
|
7
|
-
raise ArgumentError, "Can't patch unloaded gem #{gem_name}" unless gem_spec
|
11
|
+
raise Errors::GemAbsent, "Can't patch unloaded gem #{gem_name}" unless gem_spec
|
8
12
|
|
9
|
-
|
13
|
+
gem_requirement = Gem::Requirement.create(requirements)
|
14
|
+
if gem_requirement.satisfied_by?(gem_spec.version)
|
10
15
|
yield
|
11
16
|
else
|
12
17
|
message = <<~ERROR
|
@@ -14,9 +19,9 @@ module SanePatch
|
|
14
19
|
There are patches in place that need to be verified.
|
15
20
|
Make sure that the patch at #{caller_locations.first} is still needed and working.
|
16
21
|
ERROR
|
17
|
-
message += "Details
|
22
|
+
message += "Details:\n#{details}" if details
|
18
23
|
|
19
|
-
raise message
|
24
|
+
raise Errors::IncompatibleVersion, message
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
data/lib/sane_patch/version.rb
CHANGED
data/logo.png
ADDED
Binary file
|
data/sane_patch.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["hello@joel.am"]
|
11
11
|
|
12
12
|
spec.summary = %q{Making monkey patches sane again}
|
13
|
-
spec.description = %q{SanePatch will prevent gem upgrades from
|
13
|
+
spec.description = %q{SanePatch will prevent gem upgrades from silently breaking your monkey patches.}
|
14
14
|
spec.homepage = "https://github.com/Jcambass/sane_patch"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sane_patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Ambass
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description: SanePatch will prevent gem upgrades from
|
55
|
+
description: SanePatch will prevent gem upgrades from silently breaking your monkey
|
56
56
|
patches.
|
57
57
|
email:
|
58
58
|
- hello@joel.am
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".gitignore"
|
64
64
|
- ".rspec"
|
65
65
|
- ".travis.yml"
|
66
|
+
- CHANGELOG.md
|
66
67
|
- CODE_OF_CONDUCT.md
|
67
68
|
- Gemfile
|
68
69
|
- Gemfile.lock
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- Rakefile
|
72
73
|
- lib/sane_patch.rb
|
73
74
|
- lib/sane_patch/version.rb
|
75
|
+
- logo.png
|
74
76
|
- sane_patch.gemspec
|
75
77
|
homepage: https://github.com/Jcambass/sane_patch
|
76
78
|
licenses:
|