overrides_tracker 0.1.3 → 0.1.5

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: 70dce7004599affb475e97520917e99a53d822334e91a2903a3e7a5f6ade2cdd
4
- data.tar.gz: c90fe3480fb060b39a2432e2eec2ec7241b975366fca01642b412183d84154ab
3
+ metadata.gz: 52e9e378077f48a8e7c3aa3d66c8263b0a382c880d6c9a4138ab43b3aa1258bc
4
+ data.tar.gz: 9cc7d37a44eb61ef618dd90f1fe623c3e571760d3ace0af4f7f3a496dd79b196
5
5
  SHA512:
6
- metadata.gz: 401d480227c2b3dce23c37fc769c06c9ae759c94ffbe72cefcb2bf5c6b60d7964ff3a289e69cbc47ebebced807261b5c6a5a3893603adfd0880a79bf90384156
7
- data.tar.gz: fd825cfd85fdfb163a0d3ff5bc31268cf290cc83daf6d414e54ea43e9505ef7cdaa9f4dc49f9a299f61e73126070b0a5de9877b831298da73230ca9499b266c7
6
+ metadata.gz: 0bde076e4319f7a6a7f3abb5f1f2b850e28bbdc2fa99839e7b34dc4670db06d80f5669747da423e97fa62c20d28fe1778f29a0252219edd0a3b44a2a11f43eb4
7
+ data.tar.gz: cf8043ee35322037a673915b51241a2d7ec6f3ac4dafbeaca97700b8e2c24bcd8dd1a5e148d68eb0e0a7a243f990706cba027643afe01ee49a25960dc5650501
@@ -5,6 +5,7 @@ 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
+ OverridesTracker::MethodsCollector.instance.build_overrides_hash
8
9
  OverridesTracker::MethodsCollector.instance.save_to_file
9
10
 
10
11
  if ENV['OVERRIDES_API_TOKEN']
@@ -3,8 +3,8 @@ require 'net/https'
3
3
 
4
4
  class OverridesTracker::Api
5
5
 
6
- API_HOST = ENV['OVERRIDES_TRACKER_DEVELOPMENT'] ? "localhost:3000" : "overrides.io"
7
- API_PROTOCOL = ENV['OVERRIDES_TRACKER_DEVELOPMENT'] ? "http" : "https"
6
+ API_HOST = false ? "localhost:3000" : "overrides.io"
7
+ API_PROTOCOL = false ? "http" : "https"
8
8
  API_DOMAIN = "#{API_PROTOCOL}://#{API_HOST}"
9
9
 
10
10
  API_BASE = "#{API_DOMAIN}/api/v1"
@@ -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,57 @@ 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
+ else
60
+ methods = clazz.singleton_methods(false)
61
+ end
62
+
63
+ methods.each do |method_name|
64
+ if method_name != nil
65
+ method_hash = class_methods[methods_type][method_name]
66
+
67
+ if methods_type == :instance_methods
68
+ method_to_check = clazz.instance_method(method_name)
69
+ else
70
+ method_to_check = clazz.singleton_method(method_name)
71
+ end
72
+
73
+ method_to_check_hash = OverridesTracker::Util.method_hash(method_to_check)
74
+
75
+ if method_to_check_hash[:location] != nil
76
+ if (method_to_check_hash[:location][0].include? working_directory)
77
+ if method_hash != nil
78
+ if method_to_check_hash[:location] != method_hash[:location]
79
+ mark_method_as_override(methods_type, clazz.name, method_name, method_to_check, method_to_check_hash)
80
+ puts "#{method_name} of class #{clazz.name} was overridden".green
81
+ end
82
+ else
83
+ mark_method_as_added("added_#{methods_type}".to_sym, clazz.name, method_name, method_to_check, method_to_check_hash)
84
+ puts "#{method_name} of class #{clazz.name} was added".green
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ def build_overrides_hash
93
+ total_classes = @methods_collection.size
94
+ count = 0
95
+ working_directory = Dir.pwd
96
+ @methods_collection.each do |class_name, class_methods|
97
+ if class_name != nil
98
+ clazz = class_name.constantize
99
+ build_overrides_hash_for_method_type(clazz, class_methods, :instance_methods, working_directory)
100
+ build_overrides_hash_for_method_type(clazz, class_methods, :singleton_methods, working_directory)
101
+ end
102
+ count = count+1
103
+ puts "Processed #{class_name} #{count} / #{total_classes}"
104
+ end
105
+ end
69
106
 
70
107
  def overridden_methods
71
108
  @overridden_methods_collection
@@ -76,7 +113,8 @@ class OverridesTracker::MethodsCollector
76
113
  data = nil
77
114
  begin
78
115
  File.open(file_path) do |f|
79
- data = JSON.parse(f.read)
116
+ file_data = JSON.parse(f.read)
117
+ data = file_data['overridden_methods'] != nil ? file_data['overridden_methods'] : file_data
80
118
  end
81
119
  rescue
82
120
  puts "Error processing #{file_path}"
@@ -85,8 +123,18 @@ class OverridesTracker::MethodsCollector
85
123
  end
86
124
 
87
125
  def save_to_file
126
+
127
+ file_data = {}
128
+ file_data[:version] = OverridesTracker::VERSION
129
+ file_data[:branch_name] = branch_name
130
+ file_data[:branch_name_to_report] = branch_name_to_report
131
+ file_data[:last_commit_id] = last_commit_id
132
+ file_data[:last_commit_name] = last_commit_name
133
+ file_data[:last_commit_name_to_report] = last_commit_name_to_report
134
+ file_data[:overridden_methods] = @overridden_methods_collection
135
+
88
136
  File.open(path_to_report_file, "w") do |f|
89
- f << @overridden_methods_collection.to_json
137
+ f << file_data.to_json
90
138
  end
91
139
  puts ' '
92
140
  puts '==========='
@@ -104,6 +152,7 @@ class OverridesTracker::MethodsCollector
104
152
  @methods_collection[class_name] ||= {}
105
153
  @methods_collection[class_name][:instance_methods] ||= {}
106
154
  @methods_collection[class_name][:singleton_methods] ||= {}
155
+ @methods_collection[class_name][:closed] ||= 'no'
107
156
  end
108
157
 
109
158
  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.3"
2
+ VERSION = "0.1.5"
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)
@@ -90,44 +52,7 @@ if defined? OVERRIDES_TRACKER_TRACKING_ENABLED
90
52
  end
91
53
 
92
54
 
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
-
103
- def green
104
- colorize(32)
105
- end
106
55
 
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
56
 
132
57
  #Adding deep merge functionality
133
58
  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.3
4
+ version: 0.1.5
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-06 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: []