sane_patch 0.1.0 → 0.2.0

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: e05bf4fc6e133c3ae6c6ded26adc3b11647bc5258f714307011779b05f5a4bd8
4
- data.tar.gz: 2968b9196978abcd0d3b06a7871b9131cd30bc8075b95587596d084732468373
3
+ metadata.gz: dd06cfb6785effd7bfbc07c1c212ef2b43d6ca480a46b9a180d06800f2790740
4
+ data.tar.gz: '05435385730e1d6da0d6215f614e1c2a871ae2e286aeb53b2ea74af1d04ebb69'
5
5
  SHA512:
6
- metadata.gz: 4060048796877c10e0a96270bd6f44b5a389b14eccf112e88da4ba680a86eda1bbf50b4d8cbd2ae3f4854ef12062a9984c1f576f8cd22bd56eb6e81105515b6f
7
- data.tar.gz: 1b41773116b9166343b98616ac0d51f6aa4e39e5c1d66809cbe98cd56da48bd48add8e0034312bc3bdf81a0bde83e2e33c256d653fa18434cff1b464678a1e11
6
+ metadata.gz: 35d37b2964aeb895dd90b92c2b414f23c127363f83e8f2b3b9a06d9dd33b96f26450fab623cd7f63b0f2be9f45ce8ff5679277b3412767a551a9b7a9361b9fe2
7
+ data.tar.gz: '08754a0f5d071c5c4fe9bbcc6764beedc6f2014b78da60b91abcca2849228ff25ec0743d4bba0be328e7448f97406881552bc3178eaf5abfcd483ace07151fa4'
@@ -4,4 +4,16 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.6.3
7
- before_install: gem install bundler -v 2.0.1
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
@@ -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
+
@@ -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@electricfeel.com. All
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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sane_patch (0.1.0)
4
+ sane_patch (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- # Apply your patches here the same way as usual.
36
- end
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
- Greeter.greet # => 'Hello'
44
-
45
- # Let's patch the `Greeter.greet` method to output 'Hello Folks'
46
- module GreeterPatch
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
- # We currently have version 1.1.0 of the greeter gem
53
- SanePatch.patch('greeter', '1.1.0') do
54
- Greeter.prepend(GreeterPatch)
55
- end
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
- Greeter.greet # => 'Hello Folk'
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
- It looks like the greeter gem was upgraded. (RuntimeError)
63
- There are patches in place that need to be verified.
64
- Make sure that the patch at initializers/greeter_patch.rb:8 is still needed and working.
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
- Greeter.silence # => nil
92
+ Greeter.silence # => nil
73
93
 
74
- module GreeterPatch
75
- def silence
76
- ''
77
- end
94
+ module GreeterPatch
95
+ def silence
96
+ ''
78
97
  end
98
+ end
79
99
 
80
- details = <<-MSG
81
- The `silence` method should output an empty string rather than nil.
82
- This is a known issue and will be fixed in the next realase.
83
- See: https://github.com/Jcambass/greeter/issues/45
84
- MSG
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
- SanePatch.patch('greeter', '1.1.0', details: details) do
87
- Greeter.prepend(GreeterPatch)
88
- end
106
+ SanePatch.patch('greeter', '1.1.0', details: details) do
107
+ Greeter.prepend(GreeterPatch)
108
+ end
89
109
 
90
- Greeter.silence # => ''
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
- It looks like the greeter gem was upgraded. (RuntimeError)
97
- There are patches in place that need to be verified.
98
- Make sure that the patch at initializers/greeter_patch.rb:8 is still needed and working.
99
- Details:
100
- The `silence` method should output an empty string rather than nil.
101
- This is a known issue and will be fixed in the next realase.
102
- See: https://github.com/Jcambass/greeter/issues/45
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/Jambass/sane_patch/blob/master/CODE_OF_CONDUCT.md).
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).
@@ -1,12 +1,17 @@
1
1
  require "sane_patch/version"
2
2
 
3
3
  module SanePatch
4
- def self.patch(gem_name, version, details: nil)
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
- patched_version = Gem::Version.new(version)
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
- if gem_spec.version == patched_version
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: \n #{details}" if 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
@@ -1,3 +1,3 @@
1
1
  module SanePatch
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
Binary file
@@ -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 sillently breaking your monkey patches.}
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.1.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-05-23 00:00:00.000000000 Z
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 sillently breaking your monkey
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: