safe_monkey_patching 0.0.4 → 0.0.8
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/README.md +9 -3
- data/lib/safe_monkey_patching.rb +22 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c508d0db24c17c17b38f91f3a895c7199c7d15a5ec16ab290cf4277b1d484a91
|
4
|
+
data.tar.gz: 4d1da46476acbe900b87dfdd9876629f76ee18e6e91d8db661bf2969acf29def
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a45b2ea9a111a896bfe124512209696cb77e254d43476ebf107526a656d639ab1b4cff83472ca873d7393f6b88756bb7a32940d24161a74a326ae1c2100759f
|
7
|
+
data.tar.gz: 3ade656056a11a2970dbf7bd81af1fd2cbc0d936f354a7b7ab9352723cd967c9a080b7975dfa8bf405b46eff03740e37d1b519c3cc0142444e3bac01c04751e7
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ module ActiveJob
|
|
8
8
|
monkey_patch :deserialize
|
9
9
|
|
10
10
|
def deserialize(job_data)
|
11
|
-
...
|
11
|
+
# ...
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -27,7 +27,7 @@ a więc, gdy podbijemy railsy i zmieni się kod źródłowy, to `gif diff` nam o
|
|
27
27
|
|
28
28
|
```diff
|
29
29
|
|
30
|
-
diff --git a/
|
30
|
+
diff --git a/monkey_patches-old.yml b/monkey_patches-old.yml
|
31
31
|
|
32
32
|
ActiveJob::Core::ClassMethods:
|
33
33
|
deserialize:
|
@@ -35,5 +35,11 @@ diff --git a/monkey_patchs.yml b/monkey_patchs.yml
|
|
35
35
|
+ sha1: 131d3acf24768b30a3ccb1052591b1cdb603f0cd
|
36
36
|
```
|
37
37
|
|
38
|
-
|
38
|
+
Również pokażą się pliki `monkey_patches-old.yml` i `WRONG_MONKEY_PATCHES.txt`, który pokazuje niekompatybilności z gemów.
|
39
|
+
|
40
|
+
Aby zaktualizować łatki, to trzeba zcomitować `monkey_patches-old.yml` i będzie :ok:.
|
41
|
+
|
42
|
+
Dzięki temu gemu nie będzie trzeba pamiętać o przejrzeniu patchów przy podbijaniu gemów 🥳
|
43
|
+
|
44
|
+
|
39
45
|
|
data/lib/safe_monkey_patching.rb
CHANGED
@@ -45,7 +45,7 @@ module SafeMonkeyPatching
|
|
45
45
|
method_entry = { method.owner.to_s => { method.name.to_s =>
|
46
46
|
{ 'sha1' => Digest::SHA1.hexdigest(method.source) } } }
|
47
47
|
|
48
|
-
new_database = database.
|
48
|
+
new_database = database.deep_merge(method_entry)
|
49
49
|
File.open(File.join(gem_path, 'monkey_patches-new.yml'), 'w') do |f|
|
50
50
|
f.puts(new_database.to_yaml)
|
51
51
|
end
|
@@ -58,28 +58,34 @@ class Object
|
|
58
58
|
end
|
59
59
|
|
60
60
|
at_exit do
|
61
|
-
|
61
|
+
generate_file = ENV.key?('MONKEY') || ENV.key?('GITHUB_SHA')
|
62
|
+
|
62
63
|
SafeMonkeyPatching::Behavior.gems_with_patches.each do |gem_path|
|
63
|
-
old_patches = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, "monkey_patches-old.yml").sort.to_h
|
64
|
-
new_patches = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, "monkey_patches-new.yml").sort.to_h
|
64
|
+
old_patches = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, "monkey_patches-old.yml")).sort.to_h.to_yaml
|
65
|
+
new_patches = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, "monkey_patches-new.yml")).sort.to_h.to_yaml
|
65
66
|
|
66
|
-
|
67
|
-
|
67
|
+
if generate_file
|
68
|
+
File.write(File.join(gem_path, "monkey_patches-old.yml"), old_patches)
|
69
|
+
File.write(File.join(gem_path, "monkey_patches-new.yml"), new_patches)
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
+
FileUtils.mv(File.join(gem_path, "monkey_patches-new.yml"),
|
72
|
+
File.join(gem_path, "monkey_patches-old.yml"))
|
73
|
+
end
|
71
74
|
|
72
75
|
diff = Diffy::Diff.new(old_patches, new_patches)
|
73
76
|
|
74
77
|
if diff.to_s.size.positive?
|
75
|
-
$stderr.puts
|
76
|
-
$stderr.puts
|
77
|
-
$stderr.puts
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
$stderr.puts "Wrong monkey_patches! Did you changed something?".red.bold
|
79
|
+
$stderr.puts "If you want see and correct them then:"
|
80
|
+
$stderr.puts "#{"1".blue.bold}. Rerun rspec with variable #{ "MONKEY=1".green }"
|
81
|
+
$stderr.puts "#{"2".blue.bold}. Commit generated file #{ "monkey_patches-old.yml".green }"
|
82
|
+
|
83
|
+
if generate_file
|
84
|
+
open(ERROR_LOCATION, 'a') do |f|
|
85
|
+
f.puts("\n")
|
86
|
+
f.puts(gem_path)
|
87
|
+
f.puts(diff.to_s)
|
88
|
+
end
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|