visibility_predicates 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of visibility_predicates might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b7b337df42cd4e0b16e5b60640d236101a3dcd3b944fdb4b9da3972d9bb23fff
4
+ data.tar.gz: 4b2bac9ea4c8819bcb588ab3dde3c6081d6cf98b378ef0a5e008ae5b6391723c
5
+ SHA512:
6
+ metadata.gz: a41c73966f28793280a2ddfbd923cfba5b09b3fdb0f22593f021d14d95e9b24ac02bcd3eb35c3228faca484ba495bee0176b4686d906cd861c5b8bd63690e899
7
+ data.tar.gz: 5d3a8cee86ea115616aeed7476c3e930a42725414443768a1f8bb765f6b551566e0c3cb90b058eec861e86ef7e8f1b363acc1f4ce2e342fbdeee81915b1ddf50
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ coverage.data
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # bundler
17
+ vendor/
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
23
+
24
+ # tmp-old
25
+ .old
26
+
27
+ # editor
28
+ *~
29
+ .redcar
30
+
31
+ # other
32
+ *.lock
33
+ *.bak
34
+ tool/
35
+ *\#*
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - ruby-head
5
+ - 2.6
6
+ - 2.5
7
+ - rbx-3
8
+ - jruby-head
9
+
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ - rvm: rbx-3
14
+ - rvm: jruby-head
15
+
16
+ before_install:
17
+ - gem install bundler
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --readme README.md lib/**/*.rb - MIT-LICENSE
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # coding: us-ascii
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rake'
13
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT X11 License)
2
+
3
+ Copyright (c) 2012 Kenichi Kamiya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ visibility_predicates
2
+ ========================
3
+
4
+ [![Build Status](https://secure.travis-ci.org/kachick/visibility_predicates.png)](http://travis-ci.org/kachick/visibility_predicates)
5
+ [![Gem Version](https://badge.fury.io/rb/visibility_predicates.png)](http://badge.fury.io/rb/visibility_predicates)
6
+
7
+ Some predicate methods for checking method visibility.
8
+
9
+ Features
10
+ --------
11
+
12
+ * Kernel#public_method?
13
+ * Kernel#protected_method?
14
+ * Kernel#private_method?
15
+ * Module#public_instance_method?
16
+ * Module#protected_instance_method?
17
+ * Module#private_instance_method?
18
+
19
+ Usage
20
+ -----
21
+
22
+ ### Overview
23
+
24
+ ```ruby
25
+ require 'visibility_predicates'
26
+
27
+ class Foo
28
+ private; def modified_foobar; end
29
+ end
30
+
31
+ class Bar < Foo
32
+ protected :modified_foobar
33
+ end
34
+
35
+ Bar.new.public_method? :modified_foobar #=> false
36
+ Bar.new.protected_method? :modified_foobar #=> true
37
+ Bar.new.private_method? :modified_foobar #=> false
38
+ ```
39
+
40
+ Requirements
41
+ -------------
42
+
43
+ * [Ruby 2.5 or later](http://travis-ci.org/#!/kachick/visibility_predicates)
44
+
45
+ Install
46
+ -------
47
+
48
+ ```bash
49
+ gem install visibility_predicates
50
+ ```
51
+
52
+ Link
53
+ ----
54
+
55
+ * [Home](http://kachick.github.com/visibility_predicates/)
56
+ * [code](https://github.com/kachick/visibility_predicates)
57
+ * [API](http://kachick.github.com/visibility_predicates/yard/frames.html)
58
+ * [issues](https://github.com/kachick/visibility_predicates/issues)
59
+ * [CI](http://travis-ci.org/#!/kachick/visibility_predicates)
60
+ * [gem](https://rubygems.org/gems/visibility_predicates)
61
+
62
+ License
63
+ --------
64
+
65
+ The MIT X11 License
66
+ Copyright (c) 2012 Kenichi Kamiya
67
+ See MIT-LICENSE for further details.
68
+
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ # coding: us-ascii
3
+
4
+ require 'bundler/gem_tasks'
5
+
6
+ require 'rake/testtask'
7
+
8
+ task :default => [:test]
9
+
10
+ Rake::TestTask.new do |tt|
11
+ tt.verbose = true
12
+ tt.warning = true
13
+ end
@@ -0,0 +1,75 @@
1
+ # coding: us-ascii
2
+ # visibility predicates
3
+ # - Some predicate methods for checking method visibility.
4
+ # Copyright (c) 2012 Kenichi Kamiya
5
+
6
+ class Module
7
+
8
+ class << self
9
+
10
+ private
11
+
12
+ # @param [Symbol, String] visibility
13
+ # @macro [attach] _def_predicator_instance_method_visibility
14
+ # @method $1_instance_method?(name, include_inherited=true)
15
+ # @param [Symbol, String, #to_sym] name
16
+ # @param [Boolean] include_inherited
17
+ # @return [Boolean]
18
+ def _def_predicator_instance_method_visibility(visibility)
19
+ define_method :"#{visibility}_instance_method?" do |name, include_inherited=true|
20
+ sym_name = name.to_sym
21
+ public_instance_methods = public_instance_methods(include_inherited)
22
+ protected_instance_methods = protected_instance_methods(include_inherited)
23
+ private_instance_methods = private_instance_methods(include_inherited)
24
+ all_instance_methods = public_instance_methods | protected_instance_methods | private_instance_methods
25
+ unless all_instance_methods.include? sym_name
26
+ raise NameError, "'\#{sym_name}' is not defined method name in any visibilities"
27
+ end
28
+
29
+ __send__(:"#{visibility}_instance_methods").include? sym_name
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ _def_predicator_instance_method_visibility :public
36
+ _def_predicator_instance_method_visibility :protected
37
+ _def_predicator_instance_method_visibility :private
38
+
39
+ end
40
+
41
+
42
+ module Kernel
43
+
44
+ class << self
45
+
46
+ private
47
+
48
+ # @param [Symbol, String] visibility
49
+ # @macro [attach] _def_predicator_method_visibility
50
+ # @method $1_method?(name, include_inherited=true)
51
+ # @param [Symbol, String, #to_sym] name
52
+ # @param [Boolean] include_inherited
53
+ # @return [Boolean]
54
+ def _def_predicator_method_visibility(visibility)
55
+ define_method :"#{visibility}_method?" do |name, include_inherited=true|
56
+ sym_name = name.to_sym
57
+ public_methods = public_methods(include_inherited)
58
+ protected_methods = protected_methods(include_inherited)
59
+ private_methods = private_methods(include_inherited)
60
+ all_methods = public_methods | protected_methods | private_methods
61
+ unless all_methods.include? sym_name
62
+ raise NameError, "'\#{sym_name}' is not defined method name in any visibilities"
63
+ end
64
+
65
+ __send__(:"#{visibility}_methods").include? sym_name
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ _def_predicator_method_visibility :public
72
+ _def_predicator_method_visibility :protected
73
+ _def_predicator_method_visibility :private
74
+
75
+ end
@@ -0,0 +1,248 @@
1
+ # coding: us-ascii
2
+
3
+ require 'test/unit'
4
+
5
+ require "#{File.dirname(File.dirname(__FILE__))}/lib/visibility_predicates"
6
+
7
+
8
+ class Foo
9
+ def public_foo; end
10
+ protected; def protected_foo; end
11
+ private; def private_foo; end
12
+ protected; def modified_foobar; end
13
+ end
14
+
15
+ class Bar < Foo
16
+ private :modified_foobar
17
+ end
18
+
19
+ class Test_Predicate_Top_InstanceMethodVisibility < Test::Unit::TestCase
20
+
21
+ def test_public
22
+ assert_same true, Foo.public_instance_method?(:public_foo)
23
+ assert_same false, Foo.public_instance_method?(:protected_foo)
24
+ assert_same false, Foo.public_instance_method?(:private_foo)
25
+ end
26
+
27
+ def test_public_with_string_name
28
+ assert_same true, Foo.public_instance_method?('public_foo')
29
+ assert_same false, Foo.public_instance_method?('protected_foo')
30
+ assert_same false, Foo.public_instance_method?('private_foo')
31
+ end
32
+
33
+ def test_protected
34
+ assert_same false, Foo.protected_instance_method?(:public_foo)
35
+ assert_same true, Foo.protected_instance_method?(:protected_foo)
36
+ assert_same false, Foo.protected_instance_method?(:private_foo)
37
+ end
38
+
39
+ def test_private
40
+ assert_same false, Foo.private_instance_method?(:public_foo)
41
+ assert_same false, Foo.private_instance_method?(:protected_foo)
42
+ assert_same true, Foo.private_instance_method?(:private_foo)
43
+ end
44
+
45
+ def test_modified
46
+ assert_same true, Foo.protected_instance_method?(:modified_foobar)
47
+ assert_same false, Foo.private_instance_method?(:modified_foobar)
48
+ end
49
+
50
+ end
51
+
52
+
53
+ class Test_Predicate_Inherited_InstanceMethodVisibility < Test::Unit::TestCase
54
+
55
+ def test_public
56
+ assert_same true, Bar.public_instance_method?(:public_foo)
57
+ assert_same false, Bar.public_instance_method?(:protected_foo)
58
+ assert_same false, Bar.public_instance_method?(:private_foo)
59
+ end
60
+
61
+ def test_public_with_string_name
62
+ assert_same true, Bar.public_instance_method?('public_foo')
63
+ assert_same false, Bar.public_instance_method?('protected_foo')
64
+ assert_same false, Bar.public_instance_method?('private_foo')
65
+ end
66
+
67
+ def test_protected
68
+ assert_same false, Bar.protected_instance_method?(:public_foo)
69
+ assert_same true, Bar.protected_instance_method?(:protected_foo)
70
+ assert_same false, Bar.protected_instance_method?(:private_foo)
71
+ end
72
+
73
+ def test_private
74
+ assert_same false, Bar.private_instance_method?(:public_foo)
75
+ assert_same false, Bar.private_instance_method?(:protected_foo)
76
+ assert_same true, Bar.private_instance_method?(:private_foo)
77
+ end
78
+
79
+ def test_modified
80
+ assert_same false, Bar.protected_instance_method?(:modified_foobar)
81
+ assert_same true, Bar.private_instance_method?(:modified_foobar)
82
+ end
83
+
84
+ def test_public_rejected_parent
85
+ assert_raises NameError do
86
+ Bar.public_instance_method?(:public_foo, false)
87
+ end
88
+
89
+ assert_raises NameError do
90
+ Bar.public_instance_method?(:protected_foo, false)
91
+ end
92
+
93
+ assert_raises NameError do
94
+ Bar.public_instance_method?(:private_foo, false)
95
+ end
96
+ end
97
+
98
+ def test_protected_rejected_parent
99
+ assert_raises NameError do
100
+ Bar.protected_instance_method?(:public_foo, false)
101
+ end
102
+
103
+ assert_raises NameError do
104
+ Bar.protected_instance_method?(:protected_foo, false)
105
+ end
106
+
107
+ assert_raises NameError do
108
+ Bar.protected_instance_method?(:private_foo, false)
109
+ end
110
+ end
111
+
112
+ def test_private_rejected_parent
113
+ assert_raises NameError do
114
+ Bar.private_instance_method?(:public_foo, false)
115
+ end
116
+
117
+ assert_raises NameError do
118
+ Bar.private_instance_method?(:protected_foo, false)
119
+ end
120
+
121
+ assert_raises NameError do
122
+ Bar.private_instance_method?(:private_foo, false)
123
+ end
124
+ end
125
+
126
+ end
127
+
128
+
129
+
130
+ class Test_Predicate_MethodVisibility < Test::Unit::TestCase
131
+
132
+ BAR = Bar.new
133
+
134
+ class << BAR
135
+ def public_BAR; end
136
+ protected; def protected_BAR; end
137
+ private; def private_BAR; end
138
+ end
139
+
140
+ def test_public
141
+ assert_same true, BAR.public_method?(:public_foo)
142
+ assert_same false, BAR.public_method?(:protected_foo)
143
+ assert_same false, BAR.public_method?(:private_foo)
144
+ end
145
+
146
+ def test_public_with_string_name
147
+ assert_same true, BAR.public_method?('public_foo')
148
+ assert_same false, BAR.public_method?('protected_foo')
149
+ assert_same false, BAR.public_method?('private_foo')
150
+ end
151
+
152
+ def test_protected
153
+ assert_same false, BAR.protected_method?(:public_foo)
154
+ assert_same true, BAR.protected_method?(:protected_foo)
155
+ assert_same false, BAR.protected_method?(:private_foo)
156
+ end
157
+
158
+ def test_private
159
+ assert_same false, BAR.private_method?(:public_foo)
160
+ assert_same false, BAR.private_method?(:protected_foo)
161
+ assert_same true, BAR.private_method?(:private_foo)
162
+ end
163
+
164
+ def test_modified
165
+ assert_same false, BAR.protected_method?(:modified_foobar)
166
+ assert_same true, BAR.private_method?(:modified_foobar)
167
+ end
168
+
169
+ def test_public_rejected_parent
170
+ assert_raises NameError do
171
+ Bar.public_method?(:public_foo, false)
172
+ end
173
+
174
+ assert_raises NameError do
175
+ Bar.public_method?(:protected_foo, false)
176
+ end
177
+
178
+ assert_raises NameError do
179
+ Bar.public_method?(:private_foo, false)
180
+ end
181
+ end
182
+
183
+ def test_protected_rejected_parent
184
+ assert_raises NameError do
185
+ Bar.protected_method?(:public_foo, false)
186
+ end
187
+
188
+ assert_raises NameError do
189
+ Bar.protected_method?(:protected_foo, false)
190
+ end
191
+
192
+ assert_raises NameError do
193
+ Bar.protected_method?(:private_foo, false)
194
+ end
195
+ end
196
+
197
+ def test_private_rejected_parent
198
+ assert_raises NameError do
199
+ Bar.private_method?(:public_foo, false)
200
+ end
201
+
202
+ assert_raises NameError do
203
+ Bar.private_method?(:protected_foo, false)
204
+ end
205
+
206
+ assert_raises NameError do
207
+ Bar.private_method?(:private_foo, false)
208
+ end
209
+ end
210
+
211
+ def test_public_singleton
212
+ assert_same true, BAR.public_method?(:public_BAR)
213
+ assert_same false, BAR.public_method?(:protected_BAR)
214
+ assert_same false, BAR.public_method?(:private_BAR)
215
+ end
216
+
217
+ def test_protected_singleton
218
+ assert_same false, BAR.protected_method?(:public_BAR)
219
+ assert_same true, BAR.protected_method?(:protected_BAR)
220
+ assert_same false, BAR.protected_method?(:private_BAR)
221
+ end
222
+
223
+ def test_private_singleton
224
+ assert_same false, BAR.private_method?(:public_BAR)
225
+ assert_same false, BAR.private_method?(:protected_BAR)
226
+ assert_same true, BAR.private_method?(:private_BAR)
227
+ end
228
+
229
+ end
230
+
231
+
232
+ class Test_VisibilityPredicates_README < Test::Unit::TestCase
233
+
234
+ class Foo
235
+ private; def modified_foobar; end
236
+ end
237
+
238
+ class Bar < Foo
239
+ protected :modified_foobar
240
+ end
241
+
242
+ def test_overview
243
+ assert_same false, Bar.new.public_method?(:modified_foobar)
244
+ assert_same true, Bar.new.protected_method?(:modified_foobar)
245
+ assert_same false, Bar.new.private_method?(:modified_foobar)
246
+ end
247
+
248
+ end
@@ -0,0 +1,31 @@
1
+ # coding: us-ascii
2
+
3
+ Gem::Specification.new do |gem|
4
+ # specific
5
+
6
+ gem.name = 'visibility_predicates'
7
+ gem.description = 'Some predicate methods for checking method visibility.'
8
+ gem.summary = gem.description.dup
9
+ gem.license = 'MIT'
10
+ gem.version = '0.1.0'
11
+
12
+ gem.add_development_dependency 'test-unit', '>= 3.3.3', '< 4'
13
+ gem.add_development_dependency 'yard', '>= 0.9.20', '< 2'
14
+ gem.add_development_dependency 'rake', '>= 10', '< 20'
15
+ gem.add_development_dependency 'bundler', '>= 2', '< 3'
16
+
17
+ if RUBY_ENGINE == 'rbx'
18
+ gem.add_dependency 'rubysl', '~> 2.0'
19
+ gem.add_dependency 'rubysl-test-unit', '~> 2.0'
20
+ end
21
+
22
+ # common
23
+
24
+ gem.homepage = "http://kachick.github.com/#{gem.name}"
25
+ gem.authors = ['Kenichi Kamiya']
26
+ gem.email = ['kachick1+ruby@gmail.com']
27
+ gem.files = `git ls-files`.split($\)
28
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
29
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
30
+ gem.require_paths = ['lib']
31
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: visibility_predicates
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenichi Kamiya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-unit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.3.3
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.3.3
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
33
+ - !ruby/object:Gem::Dependency
34
+ name: yard
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.9.20
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '2'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.9.20
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '2'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '10'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '20'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '10'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '20'
73
+ - !ruby/object:Gem::Dependency
74
+ name: bundler
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '2'
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '2'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '3'
93
+ description: Some predicate methods for checking method visibility.
94
+ email:
95
+ - kachick1+ruby@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - ".gitignore"
101
+ - ".travis.yml"
102
+ - ".yardopts"
103
+ - Gemfile
104
+ - MIT-LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - lib/visibility_predicates.rb
108
+ - test/test_visibility_predicates.rb
109
+ - visibility_predicates.gemspec
110
+ homepage: http://kachick.github.com/visibility_predicates
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.7.6
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Some predicate methods for checking method visibility.
134
+ test_files:
135
+ - test/test_visibility_predicates.rb