visibility_monitor 0.1.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 +7 -0
- data/.gitignore +13 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/visibility_monitor_c/ext.c +51 -0
- data/ext/visibility_monitor_c/extconf.rb +3 -0
- data/lib/visibility_monitor.rb +2 -0
- data/lib/visibility_monitor/version.rb +3 -0
- data/visibility_monitor.gemspec +28 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a97c69888ffc6c2932d6639d64ad3f01e953b19ab9085dbb7c71870df7f08743
|
4
|
+
data.tar.gz: 4f423b3176100a06932e8ce2cabe5555e150e2f108ab93bf5c53983c0660cb2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b255d73acaa07d47b2dedaf6b3c0b9d0cf295ab10d846c0d5de42480ddd7b39ddfe9058802499076034500a179128546bfb1f85781637a88b698b8d275abc03
|
7
|
+
data.tar.gz: be0c1ce503a2b47591579779c3ce4a91714ff5c57c6d0dd17958f922ce498d10ebc1389acee02dc009f74147a586f045f9b509265110c7090eabcd4cdfce66d0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Dylan Thacker-Smith
|
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,69 @@
|
|
1
|
+
# VisibilityMonitor
|
2
|
+
|
3
|
+
Provides a way to monitor a module for method visibility changes with MRI ruby.
|
4
|
+
|
5
|
+
This might be useful when using Module#method_added to detect method
|
6
|
+
definitions where the visibility of the method is also of interest.
|
7
|
+
The problem is that the method visibility might be changed immediately
|
8
|
+
after the method is defined (e.g. when using `private def` to define
|
9
|
+
a private method).
|
10
|
+
|
11
|
+
Although the visibility methods (private, protected and public) can
|
12
|
+
be overridden in pure ruby code to detect visibility changes,
|
13
|
+
calling `super` doesn't change the visibility scope when the visibility
|
14
|
+
method is called without arguments (e.g. `private`). This gem works
|
15
|
+
around this limitation by overriding these visibility methods in a C
|
16
|
+
extension, so they don't interfere with setting the visibility scope.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'visibility_monitor'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install visibility_monitor
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class Example
|
38
|
+
extend VisibilityMonitor
|
39
|
+
|
40
|
+
def self.visibility_set(method_name, visibility_symbol)
|
41
|
+
puts "method :#{method_name} has been marked :#{visibility_symbol}"
|
42
|
+
end
|
43
|
+
|
44
|
+
private def example
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
52
|
+
Then, run `rake test` to run the tests. You can also run `bin/console`
|
53
|
+
for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake
|
56
|
+
install`. To release a new version, update the version number in
|
57
|
+
`version.rb`, and then run `bundle exec rake release`, which will
|
58
|
+
create a git tag for the version, push git commits and tags, and
|
59
|
+
push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at
|
64
|
+
https://github.com/dylanahsmith/visibility_monitor.
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT
|
69
|
+
License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require 'rake/extensiontask'
|
4
|
+
|
5
|
+
Rake::ExtensionTask.new("visibility_monitor_c")
|
6
|
+
|
7
|
+
Rake::TestTask.new(test: :compile) do |t|
|
8
|
+
t.libs << "test"
|
9
|
+
t.libs << "lib"
|
10
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "visibility_monitor"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
VALUE sym_public, sym_protected, sym_private;
|
4
|
+
ID intern_visibility_set;
|
5
|
+
|
6
|
+
static VALUE visibility_set(int argc, VALUE *argv, VALUE mod, VALUE visibility_sym) {
|
7
|
+
if (argc > 0) {
|
8
|
+
for (int i = 0; i < argc; i++) {
|
9
|
+
VALUE method_name = argv[i];
|
10
|
+
ID id = rb_check_id(&method_name);
|
11
|
+
if (id) {
|
12
|
+
method_name = rb_id2sym(id);
|
13
|
+
}
|
14
|
+
rb_call_super(1, &method_name);
|
15
|
+
rb_funcall(mod, intern_visibility_set, 2, method_name, visibility_sym);
|
16
|
+
}
|
17
|
+
return mod;
|
18
|
+
} else {
|
19
|
+
return rb_call_super(argc, argv);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
static VALUE monitor_public(int argc, VALUE *argv, VALUE mod) {
|
24
|
+
return visibility_set(argc, argv, mod, sym_public);
|
25
|
+
}
|
26
|
+
|
27
|
+
static VALUE monitor_protected(int argc, VALUE *argv, VALUE mod) {
|
28
|
+
return visibility_set(argc, argv, mod, sym_protected);
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE monitor_private(int argc, VALUE *argv, VALUE mod) {
|
32
|
+
return visibility_set(argc, argv, mod, sym_private);
|
33
|
+
}
|
34
|
+
|
35
|
+
static VALUE monitor_set_visibility_placeholder(VALUE mod, VALUE method_name, VALUE visibility_sym) {
|
36
|
+
return Qnil;
|
37
|
+
}
|
38
|
+
|
39
|
+
void Init_visibility_monitor_c() {
|
40
|
+
VALUE mVisibilityMonitor = rb_define_module("VisibilityMonitor");
|
41
|
+
|
42
|
+
rb_define_method(mVisibilityMonitor, "public", monitor_public, -1);
|
43
|
+
rb_define_method(mVisibilityMonitor, "protected", monitor_protected, -1);
|
44
|
+
rb_define_method(mVisibilityMonitor, "private", monitor_private, -1);
|
45
|
+
rb_define_method(mVisibilityMonitor, "visibility_set", monitor_set_visibility_placeholder, 2);
|
46
|
+
|
47
|
+
sym_public = RB_ID2SYM(rb_intern("public"));
|
48
|
+
sym_protected = RB_ID2SYM(rb_intern("protected"));
|
49
|
+
sym_private = RB_ID2SYM(rb_intern("private"));
|
50
|
+
intern_visibility_set = rb_intern("visibility_set");
|
51
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "visibility_monitor/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "visibility_monitor"
|
8
|
+
spec.version = VisibilityMonitor::VERSION
|
9
|
+
spec.authors = ["Dylan Thacker-Smith"]
|
10
|
+
spec.email = ["Dylan.Smith@shopify.com"]
|
11
|
+
|
12
|
+
spec.summary = "Provide a hook into method visibility changes"
|
13
|
+
spec.homepage = "https://github.com/dylanahsmith/visibility_monitor"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.extensions = ['ext/visibility_monitor_c/extconf.rb']
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rake-compiler", "~> 1.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: visibility_monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dylan Thacker-Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- Dylan.Smith@shopify.com
|
72
|
+
executables: []
|
73
|
+
extensions:
|
74
|
+
- ext/visibility_monitor_c/extconf.rb
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- ext/visibility_monitor_c/ext.c
|
86
|
+
- ext/visibility_monitor_c/extconf.rb
|
87
|
+
- lib/visibility_monitor.rb
|
88
|
+
- lib/visibility_monitor/version.rb
|
89
|
+
- lib/visibility_monitor/visibility_monitor.bundle
|
90
|
+
- lib/visibility_monitor_c.bundle
|
91
|
+
- visibility_monitor.gemspec
|
92
|
+
homepage: https://github.com/dylanahsmith/visibility_monitor
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.7.6
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Provide a hook into method visibility changes
|
116
|
+
test_files: []
|