called_uncalled 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ac7eebb19754d8b3bb7ad38973a96b99b313be1f437fdc04bf4c4606f12310b5
4
+ data.tar.gz: d8d10dc05f2be835da6cc2185433d0a3820980ed730a3699dc3c731e242fcec6
5
+ SHA512:
6
+ metadata.gz: 9001b8c62228958774720026d769c3b68d051288190c402a2c268c5af51aee4063594d0920b84154dc9e6cd4cff9c5ecb25fa981e732756e1424a2100fc42f9d
7
+ data.tar.gz: 7ccff283ac786867c9dad05f6235411369a32bcf3bbf5d50abd2e7f28f0a3b69e6026939408f89a84632c5cf700aeff5c0cd588fa4025957a2e1efca577dbcc0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2026-05-02
4
+
5
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "called_uncalled" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["ChapterHouse.Dune@gmail.com"](mailto:"ChapterHouse.Dune@gmail.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Frank Hall
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,158 @@
1
+ # CalledUncalled
2
+
3
+ Identify which methods for a class are being used and which are not.
4
+
5
+ ### Supports
6
+ - Directly defined methods
7
+ - Inherited methods
8
+ - Singleton methods
9
+ - Methods included from Modules
10
+ - Methods dynamically added
11
+
12
+ ## Installation
13
+
14
+ Install the gem and add to the application's Gemfile by executing:
15
+
16
+ ```bash
17
+ bundle add called_uncalled
18
+ ```
19
+
20
+ If bundler is not being used to manage dependencies, install the gem by executing:
21
+
22
+ ```bash
23
+ gem install called_uncalled
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Include called_uncalled in your Class at any location.
29
+ Execute your code as normal.
30
+ When you are interested in what methods have been called or not called use the class methods 'called_methods' and 'uncalled_methods'.
31
+ The class methods accept an array of classes or modules in the class hierarchy to filter by. The default filter is the class itself.
32
+ To list the singleton methods, pass in the results of #singleton_class. Additionally you can pass in an instance of your class to get
33
+ both the class and singleton methods combined.
34
+
35
+ Please note that
36
+
37
+ ### Example
38
+ ```ruby
39
+ module Baz
40
+
41
+ def included_called
42
+ puts 'in included_called'
43
+ end
44
+
45
+ def included_uncalled
46
+ puts 'in included_uncalled'
47
+ end
48
+
49
+ end
50
+
51
+ class Bar
52
+
53
+ def inherited_called
54
+ puts 'in inherited_called'
55
+ end
56
+
57
+ def inherited_uncalled
58
+ puts 'in inherited_uncalled'
59
+ end
60
+
61
+ end
62
+
63
+ class Foo < Bar
64
+
65
+ include Baz
66
+
67
+ def before_called
68
+ puts 'in before_called'
69
+ end
70
+
71
+ def before_uncalled
72
+ puts 'in before_uncalled'
73
+ end
74
+
75
+ include CalledUncalled
76
+
77
+ def after_called
78
+ puts 'in after_called'
79
+ end
80
+
81
+ def after_uncalled
82
+ puts 'in after_uncalled'
83
+ end
84
+
85
+ end
86
+
87
+ a = Foo.new
88
+ b = Foo.new
89
+ def a.singleton_called
90
+ puts 'in singleton_called'
91
+ end
92
+
93
+ def b.singleton_uncalled
94
+ puts 'in singleton_uncalled'
95
+ end
96
+
97
+ a.before_called
98
+ a.after_called
99
+ a.singleton_called
100
+ a.included_called
101
+ a.inherited_called
102
+
103
+ uts "\nInstance methods on #{a.class} that were called: #{Foo.called_methods}"
104
+ puts "Instance methods on #{a.class} that were not called: #{Foo.uncalled_methods}\n\n"
105
+
106
+ puts "Singleton methods on 'a' that were called: #{Foo.called_methods(a.singleton_class)}"
107
+ puts "Combined instance and singleton methods called: #{Foo.called_methods(a)}\n\n"
108
+
109
+ puts "Uncalled singleton methods on 'a': #{Foo.uncalled_methods(a.singleton_class)}"
110
+ puts "Uncalled singleton methods on 'b': #{Foo.uncalled_methods(b.singleton_class)}\n\n"
111
+
112
+ puts "Methods from Foo and Bar that were called: #{Foo.called_methods(Foo, Bar)}\n\n"
113
+ puts "All methods called #{Foo.called_methods(:all)}\n\n"
114
+ ```
115
+
116
+ Gives the following output
117
+ ```text
118
+ in before_called
119
+ in after_called
120
+ in singleton_called
121
+ in included_called
122
+ in inherited_called
123
+
124
+ Instance methods on Foo that were called: [:before_called, :after_called]
125
+ Instance methods on Foo that were not called: [:before_uncalled, :after_uncalled]
126
+
127
+ Singleton methods on 'a' that were called: [:singleton_called]
128
+ Combined instance and singleton methods called: [:before_called, :after_called, :singleton_called]
129
+
130
+ Uncalled singleton methods on 'a': []
131
+ Uncalled singleton methods on 'b': [:singleton_uncalled]
132
+
133
+ Methods from Foo and Bar that were called: [:before_called, :after_called, :inherited_called]
134
+
135
+ All methods called [:singleton_method, :singleton_class, :before_called, :after_called, :singleton_called, :included_called, :inherited_called, :class, :respond_to?, :is_a?]
136
+ ```
137
+
138
+ ## Limitations
139
+
140
+ Identically names singleton methods on multiple instances of the same class are not currently tracked separately.
141
+
142
+ ## Development
143
+
144
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
145
+
146
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
147
+
148
+ ## Contributing
149
+
150
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/called_uncalled. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/called_uncalled/blob/master/CODE_OF_CONDUCT.md).
151
+
152
+ ## License
153
+
154
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
155
+
156
+ ## Code of Conduct
157
+
158
+ Everyone interacting in the CalledUncalled project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/called_uncalled/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CalledUncalled
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "called_uncalled/version"
4
+
5
+ module CalledUncalled
6
+
7
+ def self.included(base)
8
+
9
+ base.define_singleton_method(:called_methods) do |*sources|
10
+ # Default to the class itself if no sources are given
11
+ sources.push(base) if sources.empty?
12
+ # If an instance is given, change it to be both the class and the singleton class
13
+ sources = sources.flatten.map { |source| source.is_a?(base) ? [source.class, source.singleton_class] : source }.flatten
14
+ # Select all methods that come from the given sources
15
+ base.class_variable_get(:@@called_methods).select { |m| sources.include?(:all) || sources.include?(m.owner) }.map(&:name)
16
+ end
17
+
18
+ base.define_singleton_method(:uncalled_methods) do |*sources|
19
+ # Default to the class itself if no sources are given
20
+ sources.push(base) if sources.empty?
21
+ # If an instance is given, change it to be both the class and the singleton class
22
+ sources = sources.flatten.map { |source| source.is_a?(base) ? [source.class, source.singleton_class] : source }.flatten
23
+ # Select all methods that come from the given sources
24
+ base.class_variable_get(:@@uncalled_methods).select { |m| sources.include?(:all) || sources.include?(m.owner) }.map(&:name)
25
+ end
26
+
27
+ observe = ->(base, klass, mthd) do
28
+ method_name = mthd.name
29
+ # Add the method name to uncalled methods
30
+ klass.class_variable_get(:@@uncalled_methods) << mthd
31
+ # Define a wrapping method
32
+ base.define_method(method_name) do |*args, **kwargs, &block|
33
+ # Remove ourselves from the uncalled list and add to the called list
34
+ newly_called = klass.class_variable_get(:@@uncalled_methods).find { |x| x.name == method_name }
35
+ if newly_called
36
+ klass.class_variable_get(:@@uncalled_methods).delete(newly_called)
37
+ # Add ourselves to the called list if this is the first time we were called
38
+ klass.class_variable_get(:@@called_methods).push(newly_called)
39
+ end
40
+
41
+ # Make the original call
42
+ super(*args, **kwargs, &block)
43
+ end
44
+ end
45
+
46
+ singleton_method_wrapper = Module.new
47
+
48
+ method_wrapper = Module.new do
49
+ # Track called and uncalled methods
50
+ base.class_variable_set(:@@called_methods, [])
51
+ base.class_variable_set(:@@uncalled_methods, [])
52
+
53
+ # Add the existing methods to the method wrapper
54
+ method_names = base.instance_methods
55
+ method_names.each { |method_name|
56
+ mthd = base.instance_method(method_name)
57
+ observe.call(self, base, mthd)
58
+ }
59
+
60
+ define_method(:singleton_method_added) do |method_name|
61
+ mthd = singleton_method(method_name)
62
+ # Add the new method to the existing singleton method wrapper
63
+ singleton_method_wrapper.module_eval { observe.call(self, base, mthd) }
64
+ singleton_class.prepend(singleton_method_wrapper) unless singleton_class < singleton_method_wrapper
65
+ # Special case deletion as we may be overriding the observer we added on the existing methods
66
+ newly_called = base.class_variable_get(:@@uncalled_methods).find { |x| x.name == :singleton_method_added }
67
+ if newly_called
68
+ base.class_variable_get(:@@uncalled_methods).delete(newly_called)
69
+ base.class_variable_get(:@@called_methods).push(newly_called)
70
+ end
71
+ # Call the original singleton_method_added
72
+ super(method_name)
73
+ end
74
+ end
75
+
76
+ method_added_wrapper = Module.new do
77
+ define_method(:method_added) do |method_name|
78
+ mthd = base.instance_method(method_name)
79
+ # Add the new method to the existing method wrapper
80
+ method_wrapper.module_eval { observe.call(self, base, mthd) }
81
+ # Call the original method_added
82
+ super(method_name)
83
+ end
84
+ end
85
+ # Start watching for new methods
86
+ base.singleton_class.prepend(method_added_wrapper)
87
+ # Watch all existing new singleton methods
88
+ base.prepend(method_wrapper)
89
+ end
90
+
91
+ end
@@ -0,0 +1,4 @@
1
+ module CalledUncalled
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: called_uncalled
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Frank Hall
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Track which instance and singleton methods were called and not called
13
+ including those added dynamically from other sources
14
+ email:
15
+ - ChapterHouse.Dune@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - CODE_OF_CONDUCT.md
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/called_uncalled.rb
26
+ - lib/called_uncalled/version.rb
27
+ - sig/called_uncalled.rbs
28
+ homepage: https://github.com/ChapterHouse/called_uncalled
29
+ licenses:
30
+ - MIT
31
+ metadata:
32
+ homepage_uri: https://github.com/ChapterHouse/called_uncalled
33
+ source_code_uri: https://github.com/ChapterHouse/called_uncalled
34
+ changelog_uri: https://github.com/ChapterHouse/as_ruby/CHANGELOG.md
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.2.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 4.0.6
50
+ specification_version: 4
51
+ summary: Identify methods that were called and not called
52
+ test_files: []