Skip to content

Commit

Permalink
fix added methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SyborgStudios committed Dec 7, 2022
1 parent 1415ed5 commit 12eb2e7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
1 change: 1 addition & 0 deletions bin/overrides_tracker
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if ARGV[0] == "track"
OVERRIDES_TRACKER_TRACKING_ENABLED = true
require Dir.pwd+'/config/environment.rb'
require 'overrides_tracker'

OverridesTracker::MethodsCollector.instance.build_overrides_hash
OverridesTracker::MethodsCollector.instance.save_to_file

Expand Down
8 changes: 5 additions & 3 deletions lib/overrides_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def save_methods_of_class(clazz)

single_methods = clazz.singleton_methods(false)
single_methods.each do |single_method|
method = clazz.singleton_method(single_method)
method_hash = OverridesTracker::Util.method_hash(method)
OverridesTracker::MethodsCollector.instance.add_singleton_method_for_class(clazz.name, single_method, method_hash)
if single_method != :overrides_tracker_finished_file
method = clazz.singleton_method(single_method)
method_hash = OverridesTracker::Util.method_hash(method)
OverridesTracker::MethodsCollector.instance.add_singleton_method_for_class(clazz.name, single_method, method_hash)
end
end
end
end
Expand Down
53 changes: 34 additions & 19 deletions lib/overrides_tracker/methods_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,49 @@ def build_overrides_hash_for_method_type(clazz, class_methods, methods_type, wor
methods = []
if methods_type == :instance_methods
methods = clazz.instance_methods(false)
clazz.ancestors.each do |ancestor|
if ancestor.class == Class
break
end
methods = methods + ancestor.instance_methods(false)
end
else
methods = clazz.singleton_methods(false)
clazz.ancestors.each do |ancestor|
if ancestor.class == Class
break
end
methods = methods + ancestor.singleton_methods(false)
end
end

methods.each do |method_name|
if method_name != nil
if method_name != nil && method_name != :overrides_tracker_finished_file
method_hash = class_methods[methods_type][method_name]
begin
if methods_type == :instance_methods
method_to_check = clazz.instance_method(method_name)
else
method_to_check = clazz.singleton_method(method_name)
end

if methods_type == :instance_methods
method_to_check = clazz.instance_method(method_name)
else
method_to_check = clazz.singleton_method(method_name)
end

method_to_check_hash = OverridesTracker::Util.method_hash(method_to_check)

if method_to_check_hash[:location] != nil
if method_hash != nil
if method_to_check_hash[:location] != method_hash[:location]
mark_method_as_override(methods_type, clazz.name, method_name, method_to_check, method_to_check_hash)
puts "#{method_name} of class #{clazz.name} was overridden".green
method_to_check_hash = OverridesTracker::Util.method_hash(method_to_check)

if method_to_check_hash[:location] != nil
if method_hash != nil
if method_to_check_hash[:location] != method_hash[:location]
mark_method_as_override(methods_type, clazz.name, method_name, method_to_check, method_to_check_hash)
puts "#{method_name} of class #{clazz.name} was overridden".green
end
else
if (method_to_check_hash[:location][0].include? working_directory)
mark_method_as_added("added_#{methods_type}".to_sym, clazz.name, method_name, method_to_check, method_to_check_hash)
puts "#{method_name} of class #{clazz.name} was added".green
end
end
else
#if (method_to_check_hash[:location][0].include? working_directory)
mark_method_as_added("added_#{methods_type}".to_sym, clazz.name, method_name, method_to_check, method_to_check_hash)
puts "#{method_name} of class #{clazz.name} was added".green
#end
end
rescue Exception => e
#puts "Error processing #{method_name} of class #{clazz.name}".red
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/overrides_tracker/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module OverridesTracker
VERSION = "0.1.5"
VERSION = "0.1.6"
end

0 comments on commit 12eb2e7

Please sign in to comment.