overrides_tracker 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de906983bd67adacd693b79f6171a0a3926b55e50938914c3edb552fd9fccdda
4
+ data.tar.gz: ade3eb37f8c485ac26e3d3b5f1c35429ebf66b8c889400f605625d21f0e59231
5
+ SHA512:
6
+ metadata.gz: abf5002371dffaeebceec5accf867ee11112d70b8e394136246c7ec4cee42d5ed2ea672e4f7f165fd1338bf174463fffd4e101582b83137bc38d26bb0e3585ac
7
+ data.tar.gz: 22869fe1494e6098e5f3cecbd055873cd81f65edb8f22f7f1e298a95b3e3b8901ebfac0f93be6dbdce73bb99128ac1fa9db08306f18cbb35a528f2b9d5713ea7
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.8
7
+ before_install: gem install bundler -v 1.17.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # Overrides Tracker
2
+ Overrides Tracker keeps track of all overriding methods in your project and allows for comparison across branches.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at meyborg@syborgstudios.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in overrides_tracker.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Simon Meyborg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Simon Meyborg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # Overrides Tracker
2
+ Overrides Tracker keeps track of all overriding methods in your project and allows for comparison across branches.
3
+
4
+ ## Contact
5
+
6
+ *Code and Bug Reports*
7
+
8
+ * [Issue Tracker](https://github.com/SyborgStudios/overrides_tracker/issues)
9
+ * See [CONTRIBUTING]
10
+
11
+
12
+ Getting started
13
+ ---------------
14
+ 1. Add OverridesTracker to your Gemfile and bundle install:
15
+
16
+ ```ruby
17
+ gem 'overrides_tracker', group: [:test, :development]
18
+ ```
19
+ 2. Add `overrides_tracker/*.otf` to your .gitignore file because you do won't to keep hold of your report file when changing branches.
20
+
21
+ 3. Track you overrides by running:
22
+ ```ruby
23
+ bundle exec overrides_tracker track
24
+ ```
25
+
26
+ The output will look like this.
27
+
28
+ ```
29
+ Reading all methods...
30
+ Checking...AClass
31
+ Checking...BClass
32
+ Method is a new instance method: AClass#a_new_method
33
+ Method is instance override: AClass#a_instance_method_override
34
+ .
35
+ .
36
+ .
37
+ Checking...YClass
38
+ Method is a new singleton method: YClass#a_new_method
39
+ Method is singleton override: YClass#a_singelton_method_override
40
+ Checking...ZClass
41
+
42
+ ===========
43
+ Report saved to /PATH_TO_PROJECT/overrides_tracker/BRANCH_NAME#LAST_COMMIT_ID.otf
44
+ ```
45
+
46
+ 4. This will create a folder called overrides_tracker and creates a file containing all overriding methods of your branch.
47
+
48
+ 5. Switch branch and follow steps 1-3 again. If you want to compare multiple branches you need to redo these steps for every branch.
49
+
50
+ 6. Now you have at least 2 files in the overrides_tracker folder
51
+
52
+ 7. It's time to compare these overrides accross branches.
53
+ ```ruby
54
+ bundle exec overrides_tracker compare
55
+ ````
56
+
57
+ 8. The result gives you an overview on what has changed and what not.
58
+
59
+ ```
60
+ ===========================================================================================
61
+
62
+ 1) BClass#a_instance_method_override: No Changes
63
+
64
+ ===========================================================================================
65
+
66
+ 2)....
67
+ .
68
+ .
69
+ .
70
+
71
+ ===========================================================================================
72
+
73
+ 26) YClass#a_singelton_method_override: Changes between files
74
+
75
+ in: master#528a0206d8f7cfe08737193659f85e28ccb260eb.otf
76
+ YClass#a_singelton_method_override:
77
+
78
+ Source:
79
+ def self.a_singelton_method_override
80
+ does_stuff_one_way
81
+ end
82
+
83
+ ../.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/bundler/gems/some_gem/lib/some_gem/y_class.rb:2
84
+
85
+ Override:
86
+ def self.a_singelton_method_override
87
+ does_stuff_one_way_but_slitly_different
88
+ end
89
+
90
+ /PATH_TO_PROJECT/app/models/decorators/y_class_decorator.rb:13
91
+
92
+
93
+ in: upgrade_to_latest#beadcdd8e07a2c9dc2aefddeef04fc42e6fff0d5.otf
94
+ YClass#a_singelton_method_override:
95
+
96
+ Source:
97
+ def self.a_singelton_method_override
98
+ does_stuff_in_a_different_way
99
+ end
100
+
101
+ ../.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/bundler/gems/some_gem/lib/some_gem/y_class.rb:2
102
+
103
+ Override:
104
+ def self.a_singelton_method_override
105
+ does_stuff_one_way_but_slitly_different
106
+ end
107
+
108
+ /PATH_TO_PROJECT/app/models/decorators/y_class_decorator.rb:13
109
+
110
+ ===========================================================================================
111
+
112
+ Summary:
113
+ Found 29 distinct overridden methods
114
+ 10 overridden methods have not changed
115
+ 19 overridden methods have changed
116
+ 1 where method is not an override
117
+ 4 where method is not in codebase
118
+ 15 source method bodies have changed
119
+ ```
120
+
121
+ ## Ruby version compatibility
122
+
123
+ OverridesTracker is built in [Continuous Integration] on Ruby 2.3+.
124
+
125
+ ## Code of Conduct
126
+
127
+ Everyone participating in this project's development, issue trackers and other channels is expected to follow our
128
+ [Code of Conduct](./CODE_OF_CONDUCT.md)
129
+
130
+ ## Contributing
131
+
132
+ 1. Fork it
133
+ 2. Create your feature branch (git checkout -b my-new-feature)
134
+ 3. Commit your changes (git commit -am 'Add some feature')
135
+ 4. Push to the branch (git push origin my-new-feature)
136
+ 5. Create new Pull Request
137
+
138
+ ## Copyright
139
+
140
+ Copyright (c) 2022 Simon Meyborg. See MIT-LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "overrides_tracker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ if ARGV[0] == "track"
3
+ # We set this constant so monkey patching of the gem is only done when checking the overrides
4
+ puts 'Reading all methods...'
5
+ OVERRIDES_TRACKER_TRACKING_ENABLED = true
6
+ require Dir.pwd+'/config/environment.rb'
7
+ require 'overrides_tracker'
8
+ OverridesTracker::MethodsCollector.instance.save_to_file
9
+
10
+ elsif ARGV[0] == "compare"
11
+ require 'overrides_tracker'
12
+ OverridesTracker::Comparer.compare
13
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,115 @@
1
+ class OverridesTracker::Comparer
2
+ DO_BASE_DIR = File.join(Dir.pwd, "/overrides_tracker")
3
+
4
+ def self.compare
5
+ all_methods_collections = {}
6
+ unified_methods_collections = {}
7
+ report_files = Dir.entries(DO_BASE_DIR) - [".", ".."]
8
+ report_files.each do |file_name|
9
+ if file_name[-4..-1] == '.otf'
10
+ all_methods_collections[file_name] = {}
11
+ method_collection = OverridesTracker::MethodsCollector.instance.load_from_file(file_name)
12
+ all_methods_collections[file_name] = method_collection
13
+ unified_methods_collections = unified_methods_collections.deep_merge(method_collection)
14
+ end
15
+ end
16
+
17
+ same_source_count = 0
18
+ errored_source_count = 0
19
+ method_not_available_count = 0
20
+ method_not_override_count = 0
21
+ source_changed_count = 0
22
+
23
+ methods_count = 0
24
+ classes_count = 0
25
+
26
+ unified_methods_collections.each do |unified_class_name, unified_class_hash|
27
+
28
+ if unified_class_hash['instance_methods'].any? || unified_class_hash['singleton_methods'].any?
29
+ classes_count +=1
30
+ ['instance_methods', 'singleton_methods'].each do |method_type|
31
+ unified_class_hash[method_type].each do |unified_method_name, unified_method_hash|
32
+
33
+ methods_count += 1
34
+ puts ""
35
+ puts "==========================================================================================="
36
+ puts ""
37
+ same_source_every_where = true
38
+
39
+
40
+ all_methods_collections.each do |file_name, all_methods_hash|
41
+ if all_methods_hash[unified_class_name].nil? || all_methods_hash[unified_class_name][method_type][unified_method_name].nil? || all_methods_hash[unified_class_name][method_type][unified_method_name]['sha'] != unified_method_hash['sha']
42
+ same_source_every_where = false
43
+ end
44
+ end
45
+
46
+ if same_source_every_where
47
+ puts "#{methods_count}) #{unified_class_name}##{unified_method_name}: No Changes".green.bold
48
+ same_source_count += 1
49
+ else
50
+ errored_output = nil
51
+
52
+ puts "#{methods_count}) #{unified_class_name}##{unified_method_name}: Changes between files".red.bold
53
+
54
+ all_methods_collections.each do |file_name, all_methods_hash|
55
+ puts ""
56
+ puts ("in: "+file_name).bold
57
+
58
+ if all_methods_hash[unified_class_name].nil?
59
+ puts "#{unified_class_name}##{unified_method_name}: method is not in codebase"
60
+ method_not_available_count +=1
61
+ elsif !all_methods_hash[unified_class_name][method_type][unified_method_name].nil?
62
+ puts "#{unified_class_name}##{unified_method_name}:"
63
+ puts ""
64
+ puts "Source:".bold
65
+ puts "#{all_methods_hash[unified_class_name][method_type][unified_method_name]['body']}"
66
+ puts ""
67
+ puts "#{all_methods_hash[unified_class_name][method_type][unified_method_name]['location'][0]}:#{all_methods_hash[unified_class_name][method_type][unified_method_name]['location'][1]}".italic
68
+
69
+ puts ""
70
+ puts "Override:".bold
71
+ puts "#{all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_body']}"
72
+ puts ""
73
+ puts "#{all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_location'][0]}:#{all_methods_hash[unified_class_name][method_type][unified_method_name]['overriding_location'][1]}".italic
74
+
75
+ source_changed_count +=1
76
+ elsif !all_methods_hash[unified_class_name]["added_#{method_type}"][unified_method_name].nil?
77
+ puts "#{unified_class_name}##{unified_method_name}: method is not an override"
78
+ method_not_override_count +=1
79
+
80
+ puts ""
81
+ puts "Code:".bold
82
+ puts "#{all_methods_hash[unified_class_name]["added_#{method_type}"][unified_method_name]['body']}"
83
+ puts ""
84
+ # puts "#{all_methods_hash[unified_class_name]["added_#{method_type}"][unified_method_name]['location'][0]}:#{all_methods_hash[unified_class_name][method_type][unified_method_name]['location'][1]}".italic
85
+
86
+ elsif all_methods_hash[unified_class_name]["added_#{method_type}"][unified_method_name].nil?
87
+ puts "#{unified_class_name}##{unified_method_name}: method is not in codebase"
88
+ method_not_available_count +=1
89
+ else
90
+ puts "#{unified_class_name}##{unified_method_name}: #{all_methods_hash[unified_class_name][method_type][unified_method_name]}"
91
+ end
92
+ puts ""
93
+
94
+ end
95
+ errored_source_count += 1
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ puts ""
103
+ puts "==========================================================================================="
104
+ puts ""
105
+ puts "Summary:".bold
106
+ puts "Found #{methods_count} distinct overridden methods in #{classes_count} Files"
107
+ puts "#{same_source_count} overridden methods have not changed"
108
+ puts "#{errored_source_count} overridden methods have changed"
109
+ puts "#{method_not_override_count} where method is not an override"
110
+ puts "#{method_not_available_count} where method is not in codebase"
111
+ source_changed_count = errored_source_count - method_not_available_count
112
+ puts "#{source_changed_count} source method bodies have changed"
113
+ end
114
+ end
115
+
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,138 @@
1
+ class OverridesTracker::MethodsCollector
2
+ require 'json'
3
+ @instance = new
4
+
5
+ @methods_collection = {}
6
+ @overridden_methods_collection = {}
7
+
8
+ private_class_method :new
9
+
10
+ def self.instance
11
+ @instance
12
+ end
13
+
14
+ def add_instance_method_for_class(class_name, method_name, method_hash)
15
+ add_method_for_class(:instance_methods, class_name, method_name, method_hash)
16
+ end
17
+
18
+ def add_singleton_method_for_class(class_name, method_name, method_hash)
19
+ add_method_for_class(:singleton_methods, class_name, method_name, method_hash)
20
+ end
21
+
22
+ def add_method_for_class(method_type, class_name, method_name, method_hash)
23
+ methods_collection(class_name)
24
+ @methods_collection[class_name][method_type][method_name] = method_hash
25
+ end
26
+
27
+
28
+ def method_is_instance_override?(class_name, method_name)
29
+ method_is_override?(:instance_methods, class_name, method_name)
30
+ end
31
+
32
+ def method_is_singleton_override?(class_name, method_name)
33
+ method_is_override?(:singleton_methods, class_name, method_name)
34
+ end
35
+
36
+ def method_is_override?(method_type, class_name, method_name)
37
+ methods_collection(class_name)
38
+ @methods_collection[class_name][method_type][method_name].present?
39
+ end
40
+
41
+ def mark_method_as_instance_override(class_name, method_name, overriding_method, method_hash)
42
+ mark_method_as_override(:instance_methods, class_name, method_name, overriding_method, method_hash)
43
+ end
44
+
45
+ def mark_method_as_singleton_override(class_name, method_name, overriding_method, method_hash)
46
+ mark_method_as_override(:singleton_methods, class_name, method_name, overriding_method, method_hash)
47
+ end
48
+
49
+ def mark_method_as_override(method_type, class_name, method_name, overriding_method, method_hash)
50
+ overridden_methods_collection(class_name)
51
+ @overridden_methods_collection[class_name][method_type][method_name] = @methods_collection[class_name][method_type][method_name]
52
+ @overridden_methods_collection[class_name][method_type][method_name][:overriding_location] = overriding_method.source_location
53
+ @overridden_methods_collection[class_name][method_type][method_name][:overriding_body] = method_hash[:body]
54
+ end
55
+
56
+ def mark_method_as_added_instance(class_name, method_name, overriding_method, method_hash)
57
+ mark_method_as_added(:added_instance_methods, class_name, method_name, overriding_method, method_hash)
58
+ end
59
+
60
+ def mark_method_as_added_singleton(class_name, method_name, overriding_method, method_hash)
61
+ mark_method_as_added(:added_singleton_methods, class_name, method_name, overriding_method, method_hash)
62
+ end
63
+
64
+ def mark_method_as_added(method_type, class_name, method_name, overriding_method, method_hash)
65
+ overridden_methods_collection(class_name)
66
+ @overridden_methods_collection[class_name][method_type][method_name] = method_hash
67
+ @overridden_methods_collection[class_name][method_type][method_name][:overriding_location] = overriding_method.source_location
68
+ end
69
+
70
+
71
+ def overridden_methods
72
+ @overridden_methods_collection
73
+ end
74
+
75
+ def load_from_file(file_name)
76
+ file_path = File.join(Dir.pwd, "/overrides_tracker/#{file_name}")
77
+ data = nil
78
+ begin
79
+ File.open(file_path) do |f|
80
+ data = JSON.parse(f.read)
81
+ end
82
+ rescue
83
+ puts "Error processing #{file_path}"
84
+ end
85
+ data
86
+ end
87
+
88
+ def save_to_file
89
+ File.open(path_to_report_file, "w") do |f|
90
+ f << @overridden_methods_collection.to_json
91
+ end
92
+ puts ' '
93
+ puts '==========='
94
+ puts "Report saved to #{path_to_report_file}."
95
+ end
96
+
97
+ private
98
+
99
+ def methods_collection(class_name)
100
+ @methods_collection ||= {}
101
+ @methods_collection[class_name] ||= {}
102
+ @methods_collection[class_name][:instance_methods] ||= {}
103
+ @methods_collection[class_name][:singleton_methods] ||= {}
104
+ end
105
+
106
+ def overridden_methods_collection(class_name)
107
+ @overridden_methods_collection ||= {}
108
+ @overridden_methods_collection[class_name] ||= {}
109
+ @overridden_methods_collection[class_name][:instance_methods] ||= {}
110
+ @overridden_methods_collection[class_name][:singleton_methods] ||= {}
111
+ @overridden_methods_collection[class_name][:added_instance_methods] ||= {}
112
+ @overridden_methods_collection[class_name][:added_singleton_methods] ||= {}
113
+ end
114
+
115
+ def branch_name
116
+ branch = `git rev-parse --abbrev-ref HEAD`
117
+ branch.downcase.gsub('/','_').gsub(/\s+/, "")
118
+ end
119
+
120
+ def last_commit_id
121
+ commit_id = `git log --format="%H" -n 1`
122
+ commit_id.gsub(/\s+/, "")
123
+ end
124
+
125
+ def last_commit_name
126
+ commit_id = `git log --format="%s" -n 1`
127
+ commit_id.gsub(/\s+/, "")
128
+ end
129
+
130
+ def path_to_report_file
131
+ file_name = "#{branch_name}##{last_commit_id}.otf"
132
+
133
+ directory_name = File.join(Dir.pwd, "/overrides_tracker")
134
+ Dir.mkdir(directory_name) unless File.exists?(directory_name)
135
+
136
+ directory_name+"/#{file_name}"
137
+ end
138
+ end
@@ -0,0 +1,34 @@
1
+ require 'digest/sha1'
2
+
3
+ module OverridesTracker
4
+ class Util
5
+ class << self
6
+
7
+ def method_hash method
8
+ begin
9
+ {
10
+ :sha => method_sha(method),
11
+ :location => method.source_location,
12
+ :body => outdented_method_body(method),
13
+ }
14
+ rescue
15
+ {
16
+ :sha => method.hash,
17
+ :location => nil,
18
+ :body => nil,
19
+ }
20
+ end
21
+ end
22
+
23
+ def outdented_method_body method
24
+ body = method.source
25
+ indent = body.match(/^\W+/).to_s
26
+ body.lines.map{|l| l.sub(indent, '')}.join
27
+ end
28
+
29
+ def method_sha method
30
+ Digest::SHA1.hexdigest(method.source.gsub(/\s+/, ' '))
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module OverridesTracker
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,148 @@
1
+ require "overrides_tracker/version"
2
+
3
+ # dependency for extracting method bodies and comments
4
+ require 'method_source'
5
+
6
+ require "overrides_tracker/version"
7
+ require "overrides_tracker/methods_collector"
8
+ require "overrides_tracker/file_observer"
9
+ require "overrides_tracker/util"
10
+ require "overrides_tracker/comparer"
11
+
12
+
13
+ module OverridesTracker
14
+
15
+ end
16
+
17
+ # We only want to do this core ruby monkey patching when using cli
18
+ if defined? OVERRIDES_TRACKER_TRACKING_ENABLED
19
+ Object.class_eval do
20
+ class << self
21
+
22
+ def method_added(name)
23
+ begin
24
+ if caller_locations(1)&.first&.absolute_path()&.include? Dir.pwd
25
+ clazz = ancestors.first
26
+ if OverridesTracker::MethodsCollector.instance.method_is_instance_override?(clazz.name, name)
27
+ puts "Method is instance override: #{clazz.name}##{name}".green
28
+ overriding_method = clazz.instance_method(name)
29
+ method_hash = OverridesTracker::Util.method_hash(overriding_method)
30
+ OverridesTracker::MethodsCollector.instance.mark_method_as_instance_override(clazz.name, name, overriding_method, method_hash)
31
+ elsif OverridesTracker::MethodsCollector.instance.method_is_singleton_override?(clazz.name, name)
32
+ puts "Method is singleton override: #{clazz.name}##{name}".green
33
+ overriding_method = clazz.singleton_method(name)
34
+ method_hash = OverridesTracker::Util.method_hash(overriding_method)
35
+ OverridesTracker::MethodsCollector.instance.mark_method_as_singleton_override(clazz.name, name, overriding_method, method_hash)
36
+ else
37
+ if clazz.singleton_methods(false).include?(name)
38
+ overriding_method = clazz.singleton_method(name)
39
+ if overriding_method.present?
40
+ method_hash = OverridesTracker::Util.method_hash(overriding_method)
41
+ puts "Method is a new singleton method: #{clazz.name}##{name}".green
42
+ OverridesTracker::MethodsCollector.instance.mark_method_as_added_singleton(clazz.name, name, overriding_method, method_hash)
43
+ end
44
+ elsif clazz.instance_methods(false).include?(name)
45
+ overriding_method = clazz.instance_method(name)
46
+ if overriding_method.present?
47
+ method_hash = OverridesTracker::Util.method_hash(overriding_method)
48
+ puts "Method is a new instance method: #{clazz.name}##{name}".green
49
+ OverridesTracker::MethodsCollector.instance.mark_method_as_added_instance(clazz.name, name, overriding_method, method_hash)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ rescue
55
+ puts "Error: Can not process ##{name}".red
56
+ end
57
+
58
+ super
59
+ end
60
+
61
+ def inherited(subclass)
62
+ subclass.class_eval do
63
+ def self.overrides_tracker_finished_file
64
+ clazz = ancestors.first
65
+ save_methods_of_class(clazz)
66
+ end
67
+ end
68
+ subclass.extend OverridesTracker::FileObserver
69
+ end
70
+
71
+ def save_methods_of_class(clazz)
72
+ puts "Checking...#{clazz.name}"
73
+ inst_methods = clazz.instance_methods(false)
74
+ inst_methods.each do |inst_method|
75
+ method = clazz.instance_method(inst_method)
76
+ method_hash = OverridesTracker::Util.method_hash(method)
77
+ OverridesTracker::MethodsCollector.instance.add_instance_method_for_class(clazz.name, inst_method, method_hash)
78
+ end
79
+
80
+ single_methods = clazz.singleton_methods(false)
81
+ single_methods.each do |single_method|
82
+ method = clazz.singleton_method(single_method)
83
+ method_hash = OverridesTracker::Util.method_hash(method)
84
+ OverridesTracker::MethodsCollector.instance.add_singleton_method_for_class(clazz.name, single_method, method_hash)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+
92
+ String.class_eval do
93
+ # colorization
94
+ def colorize(color_code)
95
+ "\e[#{color_code}m#{self}\e[0m"
96
+ end
97
+
98
+ def red
99
+ colorize(31)
100
+ end
101
+
102
+ def green
103
+ colorize(32)
104
+ end
105
+
106
+ def yellow
107
+ colorize(33)
108
+ end
109
+
110
+ def blue
111
+ colorize(34)
112
+ end
113
+
114
+ def pink
115
+ colorize(35)
116
+ end
117
+
118
+ def light_blue
119
+ colorize(36)
120
+ end
121
+
122
+ def bold
123
+ "\e[1m#{self}\e[22m"
124
+ end
125
+
126
+ def italic
127
+ "\e[3m#{self}\e[23m"
128
+ end
129
+ end
130
+
131
+ #Adding deep merge functionality
132
+ Hash.class_eval do
133
+ def deep_merge(other_hash, &block)
134
+ dup.deep_merge!(other_hash, &block)
135
+ end
136
+
137
+ def deep_merge!(other_hash, &block)
138
+ merge!(other_hash) do |key, this_val, other_val|
139
+ if this_val.is_a?(Hash) && other_val.is_a?(Hash)
140
+ this_val.deep_merge(other_val, &block)
141
+ elsif block_given?
142
+ block.call(key, this_val, other_val)
143
+ else
144
+ other_val
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,45 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "overrides_tracker/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "overrides_tracker"
8
+ spec.version = OverridesTracker::VERSION
9
+ spec.authors = ["Simon Meyborg"]
10
+ spec.email = ["meyborg@syborgstudios.com"]
11
+
12
+ spec.summary = 'Overrides Tracker keeps track of all overriding methods in your project and allows for comparison across branches.'
13
+ spec.description = 'Overrides Tracker keeps track of all overriding methods in your project and allows for comparison across branches.'
14
+ spec.homepage = "https://github.com/SyborgStudios/overrides_tracker"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = spec.homepage
24
+ spec.metadata["changelog_uri"] = "https://github.com/SyborgStudios/overrides_tracker/CHANGELOG.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+
33
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
34
+ `git ls-files -z`.split("\x0")
35
+ end
36
+
37
+ spec.bindir = "bin"
38
+ spec.executables = ['overrides_tracker']
39
+ spec.require_paths = ["lib"]
40
+
41
+ spec.add_development_dependency "bundler", "~> 1.17"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_dependency "method_source"
45
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.describe OverridesTracker do
2
+ it "has a version number" do
3
+ expect(OverridesTracker::VERSION).not_to be nil
4
+ end
5
+
6
+ it "does something useful" do
7
+ expect(false).to eq(true)
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "overrides_tracker"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: overrides_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Simon Meyborg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: method_source
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Overrides Tracker keeps track of all overriding methods in your project
70
+ and allows for comparison across branches.
71
+ email:
72
+ - meyborg@syborgstudios.com
73
+ executables:
74
+ - overrides_tracker
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - CHANGELOG.md
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - LICENSE
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/overrides_tracker
90
+ - bin/setup
91
+ - lib/overrides_tracker.rb
92
+ - lib/overrides_tracker/comparer.rb
93
+ - lib/overrides_tracker/file_observer.rb
94
+ - lib/overrides_tracker/methods_collector.rb
95
+ - lib/overrides_tracker/util.rb
96
+ - lib/overrides_tracker/version.rb
97
+ - overrides_tracker.gemspec
98
+ - spec/overrides_tracker_spec.rb
99
+ - spec/spec_helper.rb
100
+ homepage: https://github.com/SyborgStudios/overrides_tracker
101
+ licenses:
102
+ - MIT
103
+ metadata:
104
+ allowed_push_host: https://rubygems.org
105
+ homepage_uri: https://github.com/SyborgStudios/overrides_tracker
106
+ source_code_uri: https://github.com/SyborgStudios/overrides_tracker
107
+ changelog_uri: https://github.com/SyborgStudios/overrides_tracker/CHANGELOG.md
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.0.3.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Overrides Tracker keeps track of all overriding methods in your project and
127
+ allows for comparison across branches.
128
+ test_files: []