overrides_tracker 0.1.13 → 0.2.1

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: 219f854619f81277c8acbec980e72ecd29baff6ce9977a5411dc75108c367a97
4
- data.tar.gz: 6df617ee3d8c9859cd0e9e02e5209a5a19679cc7f5a7e657da3a53892ab049c1
3
+ metadata.gz: 0610c4769438451ae2d9da015bb36a81ebded6970f032559df5b14723425f3e4
4
+ data.tar.gz: db91e26d5db6d1cbd4aa9852bec2f74823908324c2431c39ae3a9107dde6750f
5
5
  SHA512:
6
- metadata.gz: 19c3852c01f26cd97c46e95367294a7246d277e9e0c47f8d5e3b65e80d0c899a5344bd82eafdadea51e784e88c745f6a4fac7115342135ba657d6d92f2c83002
7
- data.tar.gz: f1a918217ab3df5971148dc95a95276ba5d2de07d973bd6a631a4789252cfce1f6985ac0c6f01466eaf439f1495dbbda1fc9bc2c5343979c718ed4ddc8b6dc6e
6
+ metadata.gz: 760b81000b4500942c4aa8796ede3ca320289aa01b5922c59ae1e7524725d1dfdd338a66a6da61d10955dcb2190bb3e15906b22500cf2bc81223ce9d3f807630
7
+ data.tar.gz: 21b88a7ea51bf1f6dae302693233f629746fc4bfa2561a788fa8d4550d0c4c5e0926be074bd6c2811397bd55a485a8f51e6c119382898e0334432709d5a46368
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- overrides_tracker (0.1.11)
4
+ overrides_tracker (0.2.0)
5
5
  activesupport
6
6
  method_source
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.1.7)
11
+ activesupport (6.1.7.2)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
@@ -17,7 +17,7 @@ GEM
17
17
  addressable (2.8.1)
18
18
  public_suffix (>= 2.0.2, < 6.0)
19
19
  ast (2.4.2)
20
- concurrent-ruby (1.1.10)
20
+ concurrent-ruby (1.2.0)
21
21
  coveralls_reborn (0.25.0)
22
22
  simplecov (>= 0.18.1, < 0.22.0)
23
23
  term-ansicolor (~> 1.6)
@@ -32,7 +32,7 @@ GEM
32
32
  concurrent-ruby (~> 1.0)
33
33
  json (2.6.3)
34
34
  method_source (1.0.0)
35
- minitest (5.16.3)
35
+ minitest (5.17.0)
36
36
  parallel (1.22.1)
37
37
  parser (3.1.3.0)
38
38
  ast (~> 2.4.1)
@@ -81,7 +81,7 @@ GEM
81
81
  thor (1.2.1)
82
82
  tins (1.32.1)
83
83
  sync
84
- tzinfo (2.0.5)
84
+ tzinfo (2.0.6)
85
85
  concurrent-ruby (~> 1.0)
86
86
  unicode-display_width (2.3.0)
87
87
  vcr (6.1.0)
@@ -29,6 +29,7 @@ if ARGV[0] == 'track'
29
29
  end
30
30
 
31
31
  OverridesTracker::MethodsCollector.instance.build_overrides_hash
32
+ OverridesTracker::MethodsCollector.instance.summarize_overrides
32
33
  OverridesTracker::MethodsCollector.instance.save_to_file
33
34
 
34
35
  if ENV['OVERRIDES_API_TOKEN']
@@ -140,6 +140,58 @@ overriding_method.source_location
140
140
  data
141
141
  end
142
142
 
143
+ def summarize_overrides
144
+ puts ""
145
+ puts "==========================================================================================="
146
+ puts ""
147
+ puts ""
148
+ puts "SUMMARY"
149
+ puts ""
150
+ @overridden_methods_collection.each do |class_name, class_methods|
151
+ class_methods[:instance_methods].each do |method_name, method_hash|
152
+ show_override(class_name, method_name, method_hash, '#', 'overridden')
153
+ end
154
+ class_methods[:singleton_methods].each do |method_name, method_hash|
155
+ show_override(class_name, method_name, method_hash, '.', 'overridden')
156
+ end
157
+ class_methods[:added_instance_methods].each do |method_name, method_hash|
158
+ show_override(class_name, method_name, method_hash, '#', 'added')
159
+ end
160
+ class_methods[:added_singleton_methods].each do |method_name, method_hash|
161
+ show_override(class_name, method_name, method_hash, '.', 'added')
162
+ end
163
+ end
164
+ end
165
+
166
+ def show_override(class_name, method_name, method_hash, separator = '#', word_choice = 'overridden')
167
+
168
+ puts ""
169
+ puts "==========================================================================================="
170
+ puts ""
171
+
172
+ puts "#{class_name}#{separator}#{method_name} was #{word_choice}."
173
+ unless method_hash[:body].nil?
174
+ puts "-------------------------------------------------------------------------------------------".pink
175
+ puts ''
176
+ puts 'Original:'.italic
177
+ puts ''
178
+ puts "#{method_hash[:body]}".pink
179
+ puts ''
180
+ puts "in #{method_hash[:location][0]}:#{method_hash[:location][1]}".italic
181
+ end
182
+ puts ''
183
+ puts ''
184
+ unless method_hash[:overriding_body].nil?
185
+ puts "-------------------------------------------------------------------------------------------".blue
186
+ puts ''
187
+ puts 'Override:'.italic
188
+ puts ''
189
+ puts "#{method_hash[:overriding_body]}".blue
190
+ puts ''
191
+ puts "in: #{method_hash[:overriding_location][0]}:#{method_hash[:overriding_location][1]}".italic
192
+ end
193
+ end
194
+
143
195
  def save_to_file
144
196
  file_data = {}
145
197
  file_data[:version] = OverridesTracker::VERSION
@@ -1,3 +1,3 @@
1
1
  module OverridesTracker
2
- VERSION = '0.1.13'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -5,7 +5,6 @@ require 'method_source'
5
5
 
6
6
  require 'overrides_tracker/version'
7
7
  require 'overrides_tracker/methods_collector'
8
- require 'overrides_tracker/file_observer'
9
8
  require 'overrides_tracker/string_colorizer'
10
9
  require 'overrides_tracker/util'
11
10
  require 'overrides_tracker/comparer'
@@ -20,18 +19,18 @@ if defined? OVERRIDES_TRACKER_TRACKING_ENABLED
20
19
  Object.class_eval do
21
20
  class << self
22
21
  def inherited(subclass)
22
+ puts "Reading...#{subclass.name}"
23
23
  subclass.class_eval do
24
- def self.overrides_tracker_finished_file
25
- clazz = ancestors.first
26
- save_methods_of_class(clazz)
24
+ TracePoint.trace(:end) do |t|
25
+ if subclass == t.self
26
+ save_methods_of_class(subclass)
27
+ t.disable
28
+ end
27
29
  end
28
30
  end
29
- subclass.extend OverridesTracker::FileObserver
30
31
  end
31
32
 
32
33
  def save_methods_of_class(clazz)
33
- puts "Reading...#{clazz.name}"
34
-
35
34
  inst_methods = clazz.instance_methods(false)
36
35
  inst_methods.each do |inst_method|
37
36
  method = clazz.instance_method(inst_method)
@@ -1 +1 @@
1
- {"version":"0.1.11","branch_name":"branch_name","author_name":"author_name","committer_name":"committer_name","branch_name_to_report":"master","last_commit_id":"last_commit_id","last_commit_name":"last_commit_name","last_commit_name_to_report":"last_commit_name_to_report","working_directory":"/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker","bundle_path":"/Library/Ruby/Gems/2.6.0","methods_collection":{"CustomClass":{"instance_methods":{"instance_test_method":{"sha":"3408e1f1736c6b83bc13f014e5338eec0c67393f","location":["/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker/spec/test_classes/custom_class.rb",10],"body":"def instance_test_method\n 'instance_test_method'\nend\n","is_part_of_app":true,"overriding_location":["/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker/spec/test_classes/custom_class.rb",14],"overriding_body":"def instance_override_test_method\n 'instance_override_test_method'\nend\n","overriding_sha":"75cf2b21c3033f33c155a329d8e9110ae3fb0290","overriding_is_part_of_app":true}},"singleton_methods":{},"added_instance_methods":{"instance_test_method":{"sha":"75cf2b21c3033f33c155a329d8e9110ae3fb0290","location":["/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker/spec/test_classes/custom_class.rb",14],"body":"def instance_override_test_method\n 'instance_override_test_method'\nend\n","is_part_of_app":false,"overriding_location":["/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker/spec/test_classes/custom_class.rb",14],"overriding_is_part_of_app":false}},"added_singleton_methods":{}}},"number_of_methods":1,"number_of_methods_in_app_path":1,"number_of_classes":1,"number_of_classes_in_app_path":1}
1
+ {"version":"0.2.0","branch_name":"branch_name","author_name":"author_name","committer_name":"committer_name","branch_name_to_report":"master","last_commit_id":"last_commit_id","last_commit_name":"last_commit_name","last_commit_name_to_report":"last_commit_name_to_report","working_directory":"/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker","bundle_path":"/Library/Ruby/Gems/2.6.0","methods_collection":{"CustomClass":{"instance_methods":{"instance_test_method":{"sha":"3408e1f1736c6b83bc13f014e5338eec0c67393f","location":["/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker/spec/test_classes/custom_class.rb",10],"body":"def instance_test_method\n 'instance_test_method'\nend\n","is_part_of_app":true,"overriding_location":["/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker/spec/test_classes/custom_class.rb",14],"overriding_body":"def instance_override_test_method\n 'instance_override_test_method'\nend\n","overriding_sha":"75cf2b21c3033f33c155a329d8e9110ae3fb0290","overriding_is_part_of_app":true}},"singleton_methods":{},"added_instance_methods":{},"added_singleton_methods":{}}},"number_of_methods":1,"number_of_methods_in_app_path":1,"number_of_classes":1,"number_of_classes_in_app_path":1}
@@ -99,6 +99,33 @@ describe OverridesTracker::MethodsCollector do
99
99
  end
100
100
  end
101
101
 
102
+ describe '#summarize_overrides' do
103
+ let(:instance_method) { CustomClass.instance_method(:instance_test_method) }
104
+ let(:singleton_method) { CustomClass.singleton_method(:singleton_test_method) }
105
+ let(:added_instance_method) { CustomClass.instance_method(:instance_added_test_method) }
106
+ let(:added_singleton_method) { CustomClass.singleton_method(:singleton_added_test_method) }
107
+
108
+ before do
109
+ obj.instance_variable_set(:@methods_collection, nil)
110
+ obj.instance_variable_set(:@overridden_methods_collection, nil)
111
+ obj.add_method_for_class(:singleton_methods, 'CustomClass', :singleton_test_method, OverridesTracker::Util.method_hash(singleton_method))
112
+ obj.add_method_for_class(:instance_methods, 'CustomClass', :instance_test_method, OverridesTracker::Util.method_hash(instance_method))
113
+ obj.mark_method_as_override(:singleton_methods, 'CustomClass', :singleton_test_method, singleton_method, OverridesTracker::Util.method_hash(singleton_method))
114
+ obj.mark_method_as_override(:instance_methods, 'CustomClass', :instance_test_method, instance_method, OverridesTracker::Util.method_hash(instance_method))
115
+ obj.mark_method_as_added(:added_singleton_methods, 'CustomClass', :singleton_added_test_method, added_singleton_method, OverridesTracker::Util.method_hash(added_singleton_method))
116
+ obj.mark_method_as_added(:added_instance_methods, 'CustomClass', :instance_added_test_method, added_instance_method, OverridesTracker::Util.method_hash(added_instance_method))
117
+ end
118
+
119
+ it 'calls show_override for each overridden method' do
120
+ expect(obj).to receive(:show_override).with('CustomClass', :instance_test_method, {:sha=>"3408e1f1736c6b83bc13f014e5338eec0c67393f", :location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 10], :body=>"def instance_test_method\n 'instance_test_method'\nend\n", :is_part_of_app=>true, :overriding_location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 10], :overriding_body=>"def instance_test_method\n 'instance_test_method'\nend\n", :overriding_sha=>"3408e1f1736c6b83bc13f014e5338eec0c67393f", :overriding_is_part_of_app=>true},'#', 'overridden').once.and_call_original
121
+ expect(obj).to receive(:show_override).with('CustomClass', :singleton_test_method, {:sha=>"1e331d1bb802e5d0a21a6c18f574f6ceecb4bc91", :location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 6], :body=>"def self.singleton_test_method\n 'singleton_test_method'\nend\n", :is_part_of_app=>true, :overriding_location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 6], :overriding_body=>"def self.singleton_test_method\n 'singleton_test_method'\nend\n", :overriding_sha=>"1e331d1bb802e5d0a21a6c18f574f6ceecb4bc91", :overriding_is_part_of_app=>true},'.', 'overridden').once.and_call_original
122
+ expect(obj).to receive(:show_override).with('CustomClass', :instance_added_test_method, {:sha=>"5d7709e9d44e9f718cca1876a4fdec82bbe3cf4e", :location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 18], :body=>"def instance_added_test_method\n 'instance_added_test_method'\nend\n", :is_part_of_app=>true, :overriding_location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 18], :overriding_is_part_of_app=>true},'#', 'added').once.and_call_original
123
+ expect(obj).to receive(:show_override).with('CustomClass', :singleton_added_test_method, {:sha=>"ba6efb2d378551e55ee53660d25b266b3c515da3", :location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 22], :body=>"def self.singleton_added_test_method\n 'singleton_added_test_method'\nend\n", :is_part_of_app=>true, :overriding_location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 22], :overriding_is_part_of_app=>true},'.', 'added').once.and_call_original
124
+
125
+ obj.summarize_overrides
126
+ end
127
+ end
128
+
102
129
  describe 'save and load_from_file' do
103
130
  let(:method) { CustomClass.instance_method(:instance_test_method) }
104
131
  let(:overriding_method) { CustomClass.instance_method(:instance_override_test_method) }
@@ -115,6 +142,7 @@ describe OverridesTracker::MethodsCollector do
115
142
  allow(obj).to receive(:committer_name).and_return('committer_name')
116
143
 
117
144
  obj.instance_variable_set(:@methods_collection, nil)
145
+ obj.instance_variable_set(:@overridden_methods_collection, nil)
118
146
  obj.add_method_for_class(:instance_methods, 'CustomClass', :instance_test_method, OverridesTracker::Util.method_hash(method))
119
147
  obj.mark_method_as_override(:instance_methods, 'CustomClass', :instance_test_method, overriding_method, OverridesTracker::Util.method_hash(overriding_method))
120
148
  obj.save_to_file
@@ -125,8 +153,9 @@ describe OverridesTracker::MethodsCollector do
125
153
  obj.instance_variable_set(:@overridden_methods_collection, nil)
126
154
 
127
155
  data = obj.load_from_file(file_name)
156
+
128
157
  expect(data).to eq(
129
- {"branch_name" => "branch_name","branch_name_to_report" => "master","bundle_path" => Bundler.bundle_path.to_s, "author_name" => "author_name", "committer_name" => "committer_name","last_commit_id" => "last_commit_id","last_commit_name" => "last_commit_name","last_commit_name_to_report" => "last_commit_name_to_report","methods_collection" => {"CustomClass" => {"added_instance_methods"=>{"instance_test_method"=>{"body"=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", "is_part_of_app"=>false, "location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], "overriding_is_part_of_app"=>false, "overriding_location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], "sha"=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290"}}, "added_singleton_methods"=>{}, "instance_methods"=>{"instance_test_method"=>{"body"=>"def instance_test_method\n 'instance_test_method'\nend\n", "is_part_of_app"=>true, "location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 10], "overriding_body"=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", "overriding_is_part_of_app"=>true, "overriding_location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], "overriding_sha"=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290", "sha"=>"3408e1f1736c6b83bc13f014e5338eec0c67393f"}}, "singleton_methods"=>{}}}, "version" => "#{OverridesTracker::VERSION}", "working_directory" => Dir.pwd,"number_of_classes" => 1, "number_of_classes_in_app_path" => 1, "number_of_methods" => 1, "number_of_methods_in_app_path" => 1})
158
+ {"branch_name" => "branch_name","branch_name_to_report" => "master","bundle_path" => Bundler.bundle_path.to_s, "author_name" => "author_name", "committer_name" => "committer_name","last_commit_id" => "last_commit_id","last_commit_name" => "last_commit_name","last_commit_name_to_report" => "last_commit_name_to_report","methods_collection" => {"CustomClass"=>{"added_instance_methods"=>{}, "added_singleton_methods"=>{}, "instance_methods"=>{"instance_test_method"=>{"body"=>"def instance_test_method\n 'instance_test_method'\nend\n", "is_part_of_app"=>true, "location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 10], "overriding_body"=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", "overriding_is_part_of_app"=>true, "overriding_location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], "overriding_sha"=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290", "sha"=>"3408e1f1736c6b83bc13f014e5338eec0c67393f"}}, "singleton_methods"=>{}}}, "version" => "#{OverridesTracker::VERSION}", "working_directory" => Dir.pwd,"number_of_classes" => 1, "number_of_classes_in_app_path" => 1, "number_of_methods" => 1, "number_of_methods_in_app_path" => 1})
130
159
  end
131
160
 
132
161
  end
@@ -26,6 +26,4 @@ class CustomClass
26
26
  def self.overrides_tracker_finished_file
27
27
  @overrides_tracker_finished_file_called = true
28
28
  end
29
-
30
- extend OverridesTracker::FileObserver
31
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overrides_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Meyborg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-10 00:00:00.000000000 Z
11
+ date: 2023-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,7 +66,6 @@ files:
66
66
  - lib/overrides_tracker.rb
67
67
  - lib/overrides_tracker/api.rb
68
68
  - lib/overrides_tracker/comparer.rb
69
- - lib/overrides_tracker/file_observer.rb
70
69
  - lib/overrides_tracker/hash_decorator.rb
71
70
  - lib/overrides_tracker/methods_collector.rb
72
71
  - lib/overrides_tracker/string_colorizer.rb
@@ -76,7 +75,6 @@ files:
76
75
  - overrides_tracker/branch_name#last_commit_id.otf
77
76
  - spec/overrides_tracker/api_spec.rb
78
77
  - spec/overrides_tracker/comparer_spec.rb
79
- - spec/overrides_tracker/file_observer_spec.rb
80
78
  - spec/overrides_tracker/hash_decorator_spec.rb
81
79
  - spec/overrides_tracker/methods_collector_spec.rb
82
80
  - spec/overrides_tracker/string_colorizer_spec.rb
@@ -1,10 +0,0 @@
1
- module OverridesTracker::FileObserver
2
- def self.extended(obj)
3
- TracePoint.trace(:end) do |t|
4
- if obj == t.self
5
- obj.overrides_tracker_finished_file
6
- t.disable
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require_relative '../test_classes/custom_class'
5
-
6
- describe OverridesTracker::FileObserver do
7
- it 'calls the method overrides_tracker_finished_file when the file is finished' do
8
- expect(CustomClass.instance_variable_get(:@overrides_tracker_finished_file_called)).to eq(true)
9
- end
10
- end