invisible 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/lib/invisible.rb +15 -16
- data/lib/invisible/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e928cb33873c0a9e4d6a3dac359ca80c9d14b28584c5697c9eb702ddf723e3d0
|
4
|
+
data.tar.gz: 9d74fa7b57f100fcdff73d52259099dad1495596151a8543b378748283953788
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f58a4075089d38b5f9b578782c8ac3c0afb4cf9f7d5e80ff9fb048cce63e10a8e90a0bb840c7deb485254ad2ae95b6ae9ddf1155158c56b774766544118f1895
|
7
|
+
data.tar.gz: ec1730fce3f4254437c437e08f29a0d3057dd37b93c09c07df8caea85c0bc40239a287127faa36e54be6a339f2c572182a8fab991e02978428d1c3148baeba15
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## 0.2
|
4
4
|
|
5
|
+
### 0.2.4 (October 30, 2019)
|
6
|
+
|
7
|
+
* Only dup module if prepending class has different visibility
|
8
|
+
([#6](https://github.com/shioyama/invisible/pull/6))
|
9
|
+
|
5
10
|
### 0.2.3 (October 30, 2019)
|
6
11
|
|
7
12
|
* Only prepend dup'ed module once if possible ([#5](https://github.com/shioyama/invisible/pull/5))
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -84,7 +84,8 @@ Base.prepend WithFoo
|
|
84
84
|
|
85
85
|
instance = Base.new
|
86
86
|
|
87
|
-
Base.private_method_defined?(:private_method) #
|
87
|
+
Base.private_method_defined?(:private_method) # true
|
88
|
+
instance.private_method # raises NoMethodError
|
88
89
|
instance.send(:private_method) #=> 'private with foo'
|
89
90
|
```
|
90
91
|
|
data/lib/invisible.rb
CHANGED
@@ -63,16 +63,23 @@ maintain their original visibility.
|
|
63
63
|
|
64
64
|
instance = Base.new
|
65
65
|
|
66
|
-
Base.private_method_defined?(:private_method) #
|
66
|
+
Base.private_method_defined?(:private_method) # true
|
67
|
+
instance.private_method # raises NoMethodError
|
67
68
|
instance.send(:private_method) #=> 'private with foo'
|
68
69
|
|
69
70
|
=end
|
70
71
|
def append_features(base)
|
71
|
-
|
72
|
+
private_methods, protected_methods = methods_to_hide(base)
|
73
|
+
|
74
|
+
super
|
75
|
+
|
76
|
+
base.send(:private, *private_methods)
|
77
|
+
base.send(:protected, *protected_methods)
|
72
78
|
end
|
73
79
|
|
74
80
|
def prepend_features(base)
|
75
|
-
|
81
|
+
private_methods, protected_methods = methods_to_hide(base)
|
82
|
+
return super if private_methods.empty? && protected_methods.empty?
|
76
83
|
|
77
84
|
mod = dup
|
78
85
|
|
@@ -81,23 +88,15 @@ maintain their original visibility.
|
|
81
88
|
base.const_set(mod_name, mod)
|
82
89
|
end
|
83
90
|
|
84
|
-
|
85
|
-
mod.
|
91
|
+
mod.send(:private, *private_methods)
|
92
|
+
mod.send(:protected, *protected_methods)
|
86
93
|
base.prepend mod
|
87
94
|
end
|
88
95
|
|
89
|
-
protected
|
90
|
-
attr_accessor :invisible
|
91
|
-
|
92
96
|
private
|
93
97
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
yield if block_given?
|
99
|
-
|
100
|
-
private_methods.each { |method_name| target.class_eval { private method_name } }
|
101
|
-
protected_methods.each { |method_name| target.class_eval { protected method_name } }
|
98
|
+
def methods_to_hide(mod)
|
99
|
+
[(instance_methods - private_instance_methods) & mod.private_instance_methods,
|
100
|
+
(instance_methods - protected_instance_methods) & mod.protected_instance_methods]
|
102
101
|
end
|
103
102
|
end
|
data/lib/invisible/version.rb
CHANGED