overrides_tracker 0.1.4 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22c40f48f04af34f145bc26c68acf9ebc52913bb814f21dd1a98cd687c61237c
4
- data.tar.gz: 2b50d662098bdeb7cd06597ff674ee82f9b1e69d2dc181e2e8a782578afe391c
3
+ metadata.gz: a349cfc8219a5e3c54b7fcf01e4c8bcb826ececedb3fa81e1b0a3217cbdc7cc4
4
+ data.tar.gz: 6a602b0a8a08c566f461c8246858d2bf2204a672cff70db325bee4984906215a
5
5
  SHA512:
6
- metadata.gz: 50a5c5811f4511385fc0e564c6bfe0c12d40e764bd1eb7af84ddd3057adfa1ed2b1df17af2e1fc7aa032a17956aafeb76473591312aa366ccca9695c60080d4b
7
- data.tar.gz: ebda84d5c5c899deb6fc323e28a3c74e513471839741cf77a64d8656ad56a325e9449cb500b09ed39781f6b3bb760de25fa29a2a2ba94e19209701491d748b8c
6
+ metadata.gz: d43eb13bca15ad87a32c47183090a70a23d93d33fd6717f78c1c4c668a1a9c3254fec879771ddc15ab33a782ce03f716d949efbfc8dd9245ba92c2bd722ccac8
7
+ data.tar.gz: db00cf8aed2a4a65b4536be2e7a075488db611b551f877f40682089e6ac13e390f4aeeae276f2ec01b5598974c219b0f09716398c48054ed5d52b26d5e83dae1
@@ -5,6 +5,8 @@ if ARGV[0] == "track"
5
5
  OVERRIDES_TRACKER_TRACKING_ENABLED = true
6
6
  require Dir.pwd+'/config/environment.rb'
7
7
  require 'overrides_tracker'
8
+
9
+ OverridesTracker::MethodsCollector.instance.build_overrides_hash
8
10
  OverridesTracker::MethodsCollector.instance.save_to_file
9
11
 
10
12
  if ENV['OVERRIDES_API_TOKEN']
@@ -23,20 +23,6 @@ class OverridesTracker::MethodsCollector
23
23
  @methods_collection[class_name][method_type][method_name] = method_hash
24
24
  end
25
25
 
26
-
27
- def method_is_instance_override?(class_name, method_name)
28
- method_is_override?(:instance_methods, class_name, method_name)
29
- end
30
-
31
- def method_is_singleton_override?(class_name, method_name)
32
- method_is_override?(:singleton_methods, class_name, method_name)
33
- end
34
-
35
- def method_is_override?(method_type, class_name, method_name)
36
- methods_collection(class_name)
37
- @methods_collection[class_name][method_type][method_name].present?
38
- end
39
-
40
26
  def mark_method_as_instance_override(class_name, method_name, overriding_method, method_hash)
41
27
  mark_method_as_override(:instance_methods, class_name, method_name, overriding_method, method_hash)
42
28
  end
@@ -66,6 +52,72 @@ class OverridesTracker::MethodsCollector
66
52
  @overridden_methods_collection[class_name][method_type][method_name][:overriding_location] = overriding_method.source_location
67
53
  end
68
54
 
55
+ def build_overrides_hash_for_method_type(clazz, class_methods, methods_type, working_directory)
56
+ methods = []
57
+ if methods_type == :instance_methods
58
+ methods = clazz.instance_methods(false)
59
+ clazz.ancestors.each do |ancestor|
60
+ if ancestor.class == Class
61
+ break
62
+ end
63
+ methods = methods + ancestor.instance_methods(false)
64
+ end
65
+ else
66
+ methods = clazz.singleton_methods(false)
67
+ clazz.ancestors.each do |ancestor|
68
+ if ancestor.class == Class
69
+ break
70
+ end
71
+ methods = methods + ancestor.singleton_methods(false)
72
+ end
73
+ end
74
+
75
+ methods.each do |method_name|
76
+ if method_name != nil && method_name != :overrides_tracker_finished_file
77
+ method_hash = class_methods[methods_type][method_name]
78
+ begin
79
+ if methods_type == :instance_methods
80
+ method_to_check = clazz.instance_method(method_name)
81
+ else
82
+ method_to_check = clazz.singleton_method(method_name)
83
+ end
84
+
85
+ method_to_check_hash = OverridesTracker::Util.method_hash(method_to_check)
86
+
87
+ if method_to_check_hash[:location] != nil
88
+ if method_hash != nil
89
+ if method_to_check_hash[:location] != method_hash[:location]
90
+ mark_method_as_override(methods_type, clazz.name, method_name, method_to_check, method_to_check_hash)
91
+ puts "#{method_name} of class #{clazz.name} was overridden".green
92
+ end
93
+ else
94
+ if (method_to_check_hash[:location][0].include? working_directory)
95
+ mark_method_as_added("added_#{methods_type}".to_sym, clazz.name, method_name, method_to_check, method_to_check_hash)
96
+ puts "#{method_name} of class #{clazz.name} was added".green
97
+ end
98
+ end
99
+ end
100
+ rescue Exception => e
101
+ #puts "Error processing #{method_name} of class #{clazz.name}".red
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ def build_overrides_hash
108
+ total_classes = @methods_collection.size
109
+ count = 0
110
+ working_directory = Dir.pwd
111
+ @methods_collection.each do |class_name, class_methods|
112
+ if class_name != nil
113
+ clazz = class_name.constantize
114
+ build_overrides_hash_for_method_type(clazz, class_methods, :instance_methods, working_directory)
115
+ build_overrides_hash_for_method_type(clazz, class_methods, :singleton_methods, working_directory)
116
+ end
117
+ count = count+1
118
+ puts "Processed #{class_name} #{count} / #{total_classes}"
119
+ end
120
+ end
69
121
 
70
122
  def overridden_methods
71
123
  @overridden_methods_collection
@@ -115,6 +167,7 @@ class OverridesTracker::MethodsCollector
115
167
  @methods_collection[class_name] ||= {}
116
168
  @methods_collection[class_name][:instance_methods] ||= {}
117
169
  @methods_collection[class_name][:singleton_methods] ||= {}
170
+ @methods_collection[class_name][:closed] ||= 'no'
118
171
  end
119
172
 
120
173
  def overridden_methods_collection(class_name)
@@ -0,0 +1,41 @@
1
+ module OverridesTracker::StringColorizer
2
+ def colorize(color_code)
3
+ "\e[#{color_code}m#{self}\e[0m"
4
+ end
5
+
6
+ def red
7
+ colorize(31)
8
+ end
9
+
10
+ def green
11
+ colorize(32)
12
+ end
13
+
14
+ def yellow
15
+ colorize(33)
16
+ end
17
+
18
+ def blue
19
+ colorize(34)
20
+ end
21
+
22
+ def pink
23
+ colorize(35)
24
+ end
25
+
26
+ def light_blue
27
+ colorize(36)
28
+ end
29
+
30
+ def bold
31
+ "\e[1m#{self}\e[22m"
32
+ end
33
+
34
+ def italic
35
+ "\e[3m#{self}\e[23m"
36
+ end
37
+
38
+
39
+ end
40
+
41
+ String.prepend(OverridesTracker::StringColorizer)
@@ -1,3 +1,3 @@
1
1
  module OverridesTracker
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -6,6 +6,7 @@ require 'method_source'
6
6
  require "overrides_tracker/version"
7
7
  require "overrides_tracker/methods_collector"
8
8
  require "overrides_tracker/file_observer"
9
+ require "overrides_tracker/string_colorizer"
9
10
  require "overrides_tracker/util"
10
11
  require "overrides_tracker/comparer"
11
12
  require "overrides_tracker/api"
@@ -19,46 +20,6 @@ end
19
20
  if defined? OVERRIDES_TRACKER_TRACKING_ENABLED
20
21
  Object.class_eval do
21
22
  class << self
22
-
23
- def method_added(name)
24
- begin
25
- if caller_locations(1)&.first&.absolute_path()&.include? Dir.pwd
26
- clazz = ancestors.first
27
- if OverridesTracker::MethodsCollector.instance.method_is_instance_override?(clazz.name, name)
28
- puts "Method is instance override: #{clazz.name}##{name}".green
29
- overriding_method = clazz.instance_method(name)
30
- method_hash = OverridesTracker::Util.method_hash(overriding_method)
31
- OverridesTracker::MethodsCollector.instance.mark_method_as_instance_override(clazz.name, name, overriding_method, method_hash)
32
- elsif OverridesTracker::MethodsCollector.instance.method_is_singleton_override?(clazz.name, name)
33
- puts "Method is singleton override: #{clazz.name}##{name}".green
34
- overriding_method = clazz.singleton_method(name)
35
- method_hash = OverridesTracker::Util.method_hash(overriding_method)
36
- OverridesTracker::MethodsCollector.instance.mark_method_as_singleton_override(clazz.name, name, overriding_method, method_hash)
37
- else
38
- if clazz.singleton_methods(false).include?(name)
39
- overriding_method = clazz.singleton_method(name)
40
- if overriding_method.present?
41
- method_hash = OverridesTracker::Util.method_hash(overriding_method)
42
- puts "Method is a new singleton method: #{clazz.name}##{name}".green
43
- OverridesTracker::MethodsCollector.instance.mark_method_as_added_singleton(clazz.name, name, overriding_method, method_hash)
44
- end
45
- elsif clazz.instance_methods(false).include?(name)
46
- overriding_method = clazz.instance_method(name)
47
- if overriding_method.present?
48
- method_hash = OverridesTracker::Util.method_hash(overriding_method)
49
- puts "Method is a new instance method: #{clazz.name}##{name}".green
50
- OverridesTracker::MethodsCollector.instance.mark_method_as_added_instance(clazz.name, name, overriding_method, method_hash)
51
- end
52
- end
53
- end
54
- end
55
- rescue
56
- puts "Error: Can not process ##{name}".red
57
- end
58
-
59
- super
60
- end
61
-
62
23
  def inherited(subclass)
63
24
  subclass.class_eval do
64
25
  def self.overrides_tracker_finished_file
@@ -70,7 +31,8 @@ if defined? OVERRIDES_TRACKER_TRACKING_ENABLED
70
31
  end
71
32
 
72
33
  def save_methods_of_class(clazz)
73
- puts "Checking...#{clazz.name}"
34
+ puts "Reading...#{clazz.name}"
35
+
74
36
  inst_methods = clazz.instance_methods(false)
75
37
  inst_methods.each do |inst_method|
76
38
  method = clazz.instance_method(inst_method)
@@ -80,9 +42,11 @@ if defined? OVERRIDES_TRACKER_TRACKING_ENABLED
80
42
 
81
43
  single_methods = clazz.singleton_methods(false)
82
44
  single_methods.each do |single_method|
83
- method = clazz.singleton_method(single_method)
84
- method_hash = OverridesTracker::Util.method_hash(method)
85
- OverridesTracker::MethodsCollector.instance.add_singleton_method_for_class(clazz.name, single_method, method_hash)
45
+ if single_method != :overrides_tracker_finished_file
46
+ method = clazz.singleton_method(single_method)
47
+ method_hash = OverridesTracker::Util.method_hash(method)
48
+ OverridesTracker::MethodsCollector.instance.add_singleton_method_for_class(clazz.name, single_method, method_hash)
49
+ end
86
50
  end
87
51
  end
88
52
  end
@@ -90,44 +54,7 @@ if defined? OVERRIDES_TRACKER_TRACKING_ENABLED
90
54
  end
91
55
 
92
56
 
93
- String.class_eval do
94
- # colorization
95
- def colorize(color_code)
96
- "\e[#{color_code}m#{self}\e[0m"
97
- end
98
-
99
- def red
100
- colorize(31)
101
- end
102
57
 
103
- def green
104
- colorize(32)
105
- end
106
-
107
- def yellow
108
- colorize(33)
109
- end
110
-
111
- def blue
112
- colorize(34)
113
- end
114
-
115
- def pink
116
- colorize(35)
117
- end
118
-
119
- def light_blue
120
- colorize(36)
121
- end
122
-
123
- def bold
124
- "\e[1m#{self}\e[22m"
125
- end
126
-
127
- def italic
128
- "\e[3m#{self}\e[23m"
129
- end
130
- end
131
58
 
132
59
  #Adding deep merge functionality
133
60
  Hash.class_eval do
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Simon Meyborg"]
10
10
  spec.email = ["meyborg@syborgstudios.com"]
11
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.'
12
+ spec.summary = 'Overrides Tracker monitors methods you override for changes and allows for comparison across branches.'
13
+ spec.description = 'Overrides Tracker monitors methods you override for changes and allows for comparison across branches.'
14
14
  spec.homepage = "https://github.com/SyborgStudios/overrides_tracker"
15
15
  spec.license = "MIT"
16
16
 
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.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Meyborg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-04 00:00:00.000000000 Z
11
+ date: 2022-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -24,8 +24,8 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: Overrides Tracker keeps track of all overriding methods in your project
28
- and allows for comparison across branches.
27
+ description: Overrides Tracker monitors methods you override for changes and allows
28
+ for comparison across branches.
29
29
  email:
30
30
  - meyborg@syborgstudios.com
31
31
  executables:
@@ -51,6 +51,7 @@ files:
51
51
  - lib/overrides_tracker/comparer.rb
52
52
  - lib/overrides_tracker/file_observer.rb
53
53
  - lib/overrides_tracker/methods_collector.rb
54
+ - lib/overrides_tracker/string_colorizer.rb
54
55
  - lib/overrides_tracker/util.rb
55
56
  - lib/overrides_tracker/version.rb
56
57
  - overrides_tracker.gemspec
@@ -82,6 +83,6 @@ requirements: []
82
83
  rubygems_version: 3.0.3.1
83
84
  signing_key:
84
85
  specification_version: 4
85
- summary: Overrides Tracker keeps track of all overriding methods in your project and
86
- allows for comparison across branches.
86
+ summary: Overrides Tracker monitors methods you override for changes and allows for
87
+ comparison across branches.
87
88
  test_files: []