visibility_checker 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: 0c5361039832d163132d6ed6735a0682ba89f2ba6cc25dac95f5e2a87ffd259a
4
+ data.tar.gz: db1a56409727393c6db2da6ced345647fa876698980ba567f3d64f39de82df92
5
+ SHA512:
6
+ metadata.gz: f499de1f8dfb91855e20ecd67e6158078246dfdec97c19ca2d81a37eb1685c1d081f6b85b2468ba75c086eb15b29111adc5b46846a3c88d7b7eb5c00e739cdad
7
+ data.tar.gz: ba12a25846d8f653682d1e05558168c1d66a397a538f3f3eaf6cc67b0cc4b61bbe14bf4f7a94e362b3930f31223160dcb7370270745cae9dd9d5e98f383cd8c7
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ === 1.0.0 (2020-04-16)
2
+
3
+ * Initial Public Release
data/MIT-LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2020 Jeremy Evans
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,76 @@
1
+ = VisibilityChecker
2
+
3
+ VisibilityChecker exposes a single method, visibility_changes, for returning
4
+ an array with places where any ancestor of the given class/module has changed the
5
+ visibility of any of the methods classes/modules methods.
6
+
7
+ = Installation
8
+
9
+ gem install visibility_checker
10
+
11
+ = Source Code
12
+
13
+ Source code is available on GitHub at https://github.com/jeremyevans/visibility_checker
14
+
15
+ = Usage
16
+
17
+ Here's an example showing normal use:
18
+
19
+ require 'visibility_checker'
20
+
21
+ class C
22
+ def a
23
+ end
24
+ end
25
+
26
+ VisibilityChecker.visibility_changes(C)
27
+ # => []
28
+
29
+ module M
30
+ def a
31
+ end
32
+ end
33
+ C.include M
34
+
35
+ VisibilityChecker.visibility_changes(C)
36
+ # => []
37
+
38
+ class C
39
+ private :a
40
+ end
41
+
42
+ VisibilityChecker.visibility_changes(C)
43
+ # => [#<struct VisibilityChecker::VisibilityChange
44
+ # method=:a, defined_in=M, original_visibility=:public,
45
+ # overridden_by=C, new_visibility=:private>]
46
+
47
+ You can also extend classes or modules with +VisibilityChecker+
48
+ and call +visibility_changes+ on them:
49
+
50
+ C.extend VisibilityChecker
51
+ C.visibility_changes
52
+ # => [#<struct VisibilityChecker::VisibilityChange ... >]
53
+
54
+ Or if you want to add the +visibility_changes+ method to all
55
+ classes and modules, have +Module+ include it:
56
+
57
+ Module.include VisibilityChecker
58
+ M.visibility_changes
59
+ # => []
60
+
61
+ +VisibilityChecker.visibility_changes+ accepts two keyword arguments:
62
+
63
+ stop_at :: The ancestor at which to stop for visibility changes, Object
64
+ by default.
65
+ skip_owners :: Skip reporting a visibility change if the method that
66
+ was overridden was defined in this module/class. Set to
67
+ Kernel by default as general Ruby practice is that Kernel
68
+ methods can be overridden (e.g. Enumerable#select).
69
+
70
+ = License
71
+
72
+ MIT
73
+
74
+ = Author
75
+
76
+ Jeremy Evans <code@jeremyevans.net>
@@ -0,0 +1,38 @@
1
+ module VisibilityChecker
2
+ # Structure holding data on method visibility changes
3
+ VisibilityChange = Struct.new(:method, :defined_in, :original_visibility, :overridden_by, :new_visibility)
4
+
5
+ # Return an array of VisibilityChanges for any changes in method visibility in any
6
+ # of the the ancestors of +klass+ before +stop_at+, unless the owner of the method is
7
+ # in +skip_owners+. This will be an empty array if there are no visibility changes.
8
+ def self.visibility_changes(klass, stop_at: Object, skip_owners: [Kernel])
9
+ meths = {}
10
+ changes = []
11
+
12
+ klass.ancestors.each do |mod|
13
+ break if mod == stop_at
14
+
15
+ [:public, :private, :protected].each do |vis_type|
16
+ mod.send("#{vis_type}_instance_methods").each do |meth|
17
+ prev_vis_type, prev_mod = meths[meth]
18
+ unless prev_vis_type.nil? || prev_vis_type == vis_type
19
+ owner = mod.instance_method(meth).owner
20
+ unless skip_owners.include?(owner)
21
+ changes << VisibilityChange.new(meth, mod.instance_method(meth).owner, vis_type, prev_mod, prev_vis_type)
22
+ end
23
+ end
24
+ meths[meth] = [vis_type, mod]
25
+ end
26
+ end
27
+ end
28
+
29
+ changes
30
+ end
31
+
32
+ # Detect visibility changes in the receiver's ancestors. This should only
33
+ # be used if you are extending a class or module with VisibilityChecker or
34
+ # including it in Class or Module.
35
+ def visibility_changes
36
+ VisibilityChecker.visibility_changes(self)
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: visibility_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-global_expectations
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: |
42
+ VisibilityChecker exposes a single method, visibility_changes, for returning
43
+ an array with places where any ancestor of the given class has changed the
44
+ visibility of any of the classes's methods.
45
+ email: code@jeremyevans.net
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files:
49
+ - README.rdoc
50
+ - CHANGELOG
51
+ - MIT-LICENSE
52
+ files:
53
+ - CHANGELOG
54
+ - MIT-LICENSE
55
+ - README.rdoc
56
+ - lib/visibility_checker.rb
57
+ homepage: http://github.com/jeremyevans/visibility_checker
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ bug_tracker_uri: https://github.com/jeremyevans/visibility_checker/issues
62
+ changelog_uri: https://github.com/jeremyevans/visibility_checker/blob/master/CHANGELOG
63
+ source_code_uri: https://github.com/jeremyevans/visibility_checker
64
+ post_install_message:
65
+ rdoc_options:
66
+ - "--quiet"
67
+ - "--line-numbers"
68
+ - "--inline-source"
69
+ - "--title"
70
+ - 'VisibilityChecker: Detect method visibility changes'
71
+ - "--main"
72
+ - README.rdoc
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.0.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.1.2
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Detect method visibility changes
90
+ test_files: []