safe_monkey_patching 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/safe_monkey_patching.rb +9 -5
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7ced24c8b951983501b1c890c3b0caa643f9b2e68f366465741fd5493a8e24f
4
- data.tar.gz: eda8d97d249ef17c44d909c23eb20d034f64d049ac96f862c16afaeb375dc63b
3
+ metadata.gz: cb049b9fe1a86ac335d025d222022636d7ecb8e4ef6cc7c25a86c58968090d2a
4
+ data.tar.gz: e9f903c2226c3a2750666d2f5dc63afd55d8ea8081a82082b439c3bd51cfbae3
5
5
  SHA512:
6
- metadata.gz: 754b46804461f1181097339ba7975d5f81d8f6081f443660b6392e40601f2c171cdb5c371996d89c50d3a1670154f4bde765e4c1ff9f5d21a1f1a1423c1379dd
7
- data.tar.gz: 94fc54058102b2439807d3b5d1379390c4c85f532d5d80d53a835f3612ef74097aa646a3cb4207faee4e4364bbd2b27819ea40cdcd40df7282351f9fb506d812
6
+ metadata.gz: bb8e560c538bd800ede19b5ae9f8bc2919ccd48868facd6f562cd326a80b7a409e82d957f53bc8e6ccbb4ed62d253eea041f10f103afe1d084028531e0e4c138
7
+ data.tar.gz: 753c0171e3fed5a0246ca5286d62ad59efb76a08844c31c489affbe27b86869f3b563537097e623f80e25177d29cec1a69c94ab8d69d39e2eb736895d30ac32a
@@ -30,13 +30,14 @@ module SafeMonkeyPatching
30
30
  end
31
31
 
32
32
  def monkey_patch(method_sym)
33
+ return unless Rails.env.test?
34
+
33
35
  caller = caller_locations.first.path
34
36
  gem_path = Gem::Specification.find do |spec|
35
37
  File.fnmatch(File.join(spec.full_gem_path, '*'), caller)
36
38
  end&.full_gem_path || Rails.root
37
39
 
38
40
  SafeMonkeyPatching::Behavior.add_gem_with_patch(gem_path)
39
- return unless Rails.env.test?
40
41
 
41
42
  method = instance_method(method_sym)
42
43
  database = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, 'monkey_patches-new.yml'))
@@ -57,10 +58,13 @@ class Object
57
58
  end
58
59
 
59
60
  at_exit do
60
- return unless Rails.env.test?
61
+ break unless Rails.env.test?
61
62
  SafeMonkeyPatching::Behavior.gems_with_patches.each do |gem_path|
62
- old_patches = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, "monkey_patches-old.yml")).to_yaml
63
- new_patches = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, "monkey_patches-new.yml")).to_yaml
63
+ old_patches = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, "monkey_patches-old.yml")).sort.to_h.to_yaml
64
+ new_patches = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, "monkey_patches-new.yml")).sort.to_h.to_yaml
65
+
66
+ File.write(File.join(gem_path, "monkey_patches-old.yml"), old_patches)
67
+ File.write(File.join(gem_path, "monkey_patches-new.yml"), new_patches)
64
68
 
65
69
  FileUtils.mv(File.join(gem_path, "monkey_patches-new.yml"),
66
70
  File.join(gem_path, "monkey_patches-old.yml"))
@@ -68,7 +72,7 @@ at_exit do
68
72
  diff = Diffy::Diff.new(old_patches, new_patches)
69
73
 
70
74
  if diff.to_s.size.positive?
71
- $stderr.puts 'Wrong monkeypatches!'.red.bold
75
+ $stderr.puts "Wrong monkeypatches! \n But if they are correct, then just commit 'monkey_patches-old.yml'".red.bold
72
76
  $stderr.puts gem_path
73
77
  $stderr.puts diff.to_s(:color)
74
78
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe_monkey_patching
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrzej Bisewski
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: Safe monaky patching
27
+ description: Safe monkey patching
28
28
  email: andrzej@bisewski.dev
29
29
  executables: []
30
30
  extensions: []
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.0.9
54
+ rubygems_version: 3.1.6
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: Safe monkey patching