safe_monkey_patching 0.0.4 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/lib/safe_monkey_patching.rb +22 -16
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7a27b544541b1a019556b6e4835a4fa499957fde547835dec37587fe6123c0e
4
- data.tar.gz: 7088de066fbdeccc9140c5b6321f7675fe96865ccd2c1f4b78be36f92edf5caa
3
+ metadata.gz: c508d0db24c17c17b38f91f3a895c7199c7d15a5ec16ab290cf4277b1d484a91
4
+ data.tar.gz: 4d1da46476acbe900b87dfdd9876629f76ee18e6e91d8db661bf2969acf29def
5
5
  SHA512:
6
- metadata.gz: 1d033085a48e5314ed0e307bea9b183f4b7eabfc523cc0d4161a0e2072e2df3322ab06785df40c77b385d24af42fa91015c80ccb3ea6303c3582b91a27de107d
7
- data.tar.gz: e1265bcabb0b17762463320bb989c7ee91f66a353ce96f2a1f2fc176be3187512a9b3d7d9eb10b5f7f04da7134f5077b6481750269547a9601b429f7a33640af
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/monkey_patchs.yml b/monkey_patchs.yml
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
- Dzięki temu będziemy wiedzieli, że trzeba tam zajrzeć 🥳
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
 
@@ -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.merge(method_entry)
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
- break unless Rails.env.test?
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).to_yaml
64
- new_patches = SafeMonkeyPatching::Behavior.load_store(File.join(gem_path, "monkey_patches-new.yml").sort.to_h).to_yaml
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
- 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)
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
- FileUtils.mv(File.join(gem_path, "monkey_patches-new.yml"),
70
- File.join(gem_path, "monkey_patches-old.yml"))
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 'Wrong monkeypatches!'.red.bold
76
- $stderr.puts gem_path
77
- $stderr.puts diff.to_s(:color)
78
-
79
- open(ERROR_LOCATION, 'a') do |f|
80
- f.puts("\n")
81
- f.puts(gem_path)
82
- f.puts(diff.to_s)
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
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.4
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrzej Bisewski