domesticate_monkeys 0.0.1 → 0.0.5

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: 2b075af4113a94ea0fa6dc9bdbf085b0cad3d0d15b37badffaca05ed77e656d1
4
- data.tar.gz: 2f391f15f8044dec6df881f9e81ff5ebd9a034a5ee1b555898a9e240e300070b
3
+ metadata.gz: bc7767c2c5977c095458bd62cb70a5be2b4cca06ad292f1dbb637841f217a8f8
4
+ data.tar.gz: d49517d14ce59874008da043596b4d23451107426591a197af84885eafb1f88c
5
5
  SHA512:
6
- metadata.gz: 152653bfd024299e8ce20aadda9ded6d8124c754925ba4a532ba30929ec3c8f586c00d5a61227969de12954e4bb4faa16591ec39420d3d2d97370519ce1d9758
7
- data.tar.gz: 2cab94b24d90eaa77f9122dbdf7206dbdd5e45bd04e3e4a638a5ce9d651c853927cb2935f3e7631bdb70f661d6a367f7589f35d7ddb26be03bc6d8c45ff4ca1f
6
+ metadata.gz: 58517d8b370528ac79bf05c0226812e1d37397f59612d7c927f2cc6fd928081a25ed6f33482d3ded4bb589ee93f2807c36a7a5342fecb9f3363debbe2a40f7ff
7
+ data.tar.gz: fc0e6cec64f0d9ea8ab0ea2841603998cbbd4c31633c46520f2ebb9ea1270e7ca69c2d22f4c2d89b0bf374f4371d6fa748ce5dae5f82b2374d2291225d5166b0
@@ -20,6 +20,7 @@ module DomesticateMonkeys
20
20
  parser.on("-t [COUNT]", "--top [COUNT", "show top x redefinitions") { |top| options[:top] = top }
21
21
  parser.on("-h", "--help", "show option") { puts parser; exit }
22
22
  parser.on("-v", "--version", "show version") { puts VERSION; exit }
23
+ parser.on("--skip-count-print") { $SKIP_COUNT_PRINTING = true }
23
24
  end.parse!
24
25
 
25
26
  # set default arguments
@@ -33,6 +34,10 @@ module DomesticateMonkeys
33
34
  # load application
34
35
  load MainApp
35
36
 
37
+ # validate that no gems that are known to break domesticate_monkeys are present
38
+ # (through overwriting our crucial Kernel .method_added monkey patch)
39
+ validate
40
+
36
41
  # show results
37
42
  dm_view = View.new
38
43
  dm_view.send(view)
@@ -15,9 +15,9 @@ module DomesticateMonkeys
15
15
 
16
16
  class << self
17
17
 
18
- def add(unbound_method)
19
-
20
- name = format_method_name(unbound_method)
18
+ def add(unbound_method, method_type)
19
+
20
+ name = format_method_name(unbound_method, method_type)
21
21
  source = read_method_source(unbound_method)
22
22
  return unless name && source
23
23
 
@@ -37,28 +37,22 @@ module DomesticateMonkeys
37
37
  return
38
38
  end
39
39
 
40
- def format_method_name(unbound_method)
41
-
42
- # The formatted method name serves as the uniquely identifying key for
43
- # all operations, with a distinguishing '#' for instance methods and a
44
- # '.' for singleton methods.
45
-
40
+ def format_method_name(unbound_method, method_type)
46
41
  name = unbound_method.to_s
47
42
 
48
- return format_instance_method(name) if name.include?('UnboundMethod')
49
- return format_singleton_method(name) if name.include?('Method')
43
+ return format_instance_method(name) if method_type == :instance
44
+ return format_singleton_method(name) if method_type == :singleton
50
45
  end
51
46
 
52
- def format_instance_method(name)
53
- name.slice(/(?<=#<UnboundMethod: )[^(]*/)
54
- .gsub(/\(.*\)/,'')
55
- .delete('>')
47
+ def format_instance_method(name)
48
+ regex = /.*?<UnboundMethod: ([a-zA-Z:_]{1,}).*(?>([#]))([#.a-zA-Z_?]{1,})/
49
+ name.scan(regex).flatten.join
56
50
  end
57
51
 
58
52
  def format_singleton_method(name)
59
- name.slice(/(?<=#<Method: )[^(]*/)
60
- .gsub(/\(.*\)/,'')
61
- .delete('>')
53
+ # regex = /.*?<Method:[^a-zA-Z:]{0,}([a-zA-Z:]{1,})[>]{0,1}([a-zA-Z_.]{1,})/
54
+ regex = /.*?<Method:[^a-zA-Z:]{0,}([a-zA-Z:]{1,})[^\.]*([.A-Za-z_]{1,})/
55
+ name.scan(regex).flatten.join
62
56
  end
63
57
 
64
58
  def read_method_source(unbound_method)
@@ -76,7 +70,10 @@ module DomesticateMonkeys
76
70
  def add_source(method_name, source)
77
71
 
78
72
  $DOMESTICATE_MONKEYS_COUNT += 1
79
- printf("\r Methods defined: #{$DOMESTICATE_MONKEYS_COUNT}\r") if $BOOTING_MAIN_APP
73
+
74
+ if $BOOTING_MAIN_APP && !$SKIP_COUNT_PRINTING
75
+ printf("\r Methods defined: #{$DOMESTICATE_MONKEYS_COUNT}\r")
76
+ end
80
77
 
81
78
  @method ||= method_name
82
79
 
@@ -40,7 +40,7 @@ module DomesticateMonkeys
40
40
 
41
41
  def filter_tracks_by_path(tracks, path_filter)
42
42
  tracks.select do |_method, track|
43
- track.sources.any? { |source| source.snakecase.include?(path_filter.snakecase) }
43
+ track.sources.any? { |source| source.snakecase.include?(path_filter.snakecase) && source.exclude?("/vendor/") }
44
44
  end
45
45
  end
46
46
 
@@ -1,3 +1,4 @@
1
+ require "pry"
1
2
 
2
3
  class Module
3
4
 
@@ -16,13 +17,13 @@ class Module
16
17
  # orignal definition.
17
18
 
18
19
  def method_added(_method)
19
- unbound_method = instance_method(_method)
20
- DomesticateMonkeys::Track.add(unbound_method)
20
+ unbound_method = self.instance_method(_method)
21
+ DomesticateMonkeys::Track.add(unbound_method, :instance)
21
22
  end
22
23
 
23
24
  def self.singleton_method_added(_method)
24
- unbound_method = singleton_method(_method)
25
- DomesticateMonkeys::Track.add(unbound_method)
25
+ unbound_method = self.method(_method)
26
+ DomesticateMonkeys::Track.add(unbound_method, :singleton)
26
27
  end
27
28
 
28
29
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module DomesticateMonkeys
3
3
 
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.5'
5
5
 
6
6
  end
@@ -3,8 +3,9 @@ require "domesticate_monkeys/version"
3
3
 
4
4
  module DomesticateMonkeys
5
5
 
6
- Root = File.expand_path('../', __dir__)
7
- MainApp = Root + "/lib/domesticate_monkeys/boot/main_app.rb"
6
+ Root = File.expand_path('../', __dir__)
7
+ MainApp = Root + "/lib/domesticate_monkeys/boot/main_app.rb"
8
+ ForbiddenDependencies = %w[debug]
8
9
 
9
10
  autoload :Track, "domesticate_monkeys/constants/track"
10
11
  autoload :View, "domesticate_monkeys/constants/view"
@@ -14,4 +15,16 @@ module DomesticateMonkeys
14
15
  require "domesticate_monkeys/initializers/global_variables"
15
16
  require "domesticate_monkeys/initializers/module"
16
17
 
18
+ class << self
19
+
20
+ def validate
21
+ ForbiddenDependencies.each do |dep|
22
+ if Gem.loaded_specs[dep].present?
23
+ raise StandardError, "Can't run datagaze with dependency #{dep}, since it overwrites our required Kernel monkey patch."
24
+ end
25
+ end
26
+ end
27
+
28
+ end
29
+
17
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domesticate_monkeys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer