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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72e65a804434aaa0d8ab2ffd43ac25e1d21cd9ece36ada09cc1182386c07e1d6
4
- data.tar.gz: e1379dff0e06e556fa0fa015416a4a6d598b58bf3442dc13d14aaeb676dc5f8b
3
+ metadata.gz: e928cb33873c0a9e4d6a3dac359ca80c9d14b28584c5697c9eb702ddf723e3d0
4
+ data.tar.gz: 9d74fa7b57f100fcdff73d52259099dad1495596151a8543b378748283953788
5
5
  SHA512:
6
- metadata.gz: 25eee1664224d7e3f1ef82943cdf421f77b8859d4d4a3dc6c5dc370398297556cf84ea7c9be3ea04a2b4a165b5ed03d51bec85fa3e8783eb5afade47207617cf
7
- data.tar.gz: 52173c2d4870367147ef495117703cbcc23f7dd29c110d8f4eab7b551f4eb5f07bfa19eec798d41b7a583110dc2c4dfff71252fa506cf40d7743dd9f2ea0f17b
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invisible (0.2.2)
4
+ invisible (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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) # raises NoMethodError
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) # raises NoMethodError
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
- sync_visibility(base) { super }
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
- return super if invisible
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
- sync_visibility(base, mod)
85
- mod.invisible = true
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 sync_visibility(source, target = source)
95
- private_methods = instance_methods.select { |m| source.private_method_defined? m }
96
- protected_methods = instance_methods.select { |m| source.protected_method_defined? m }
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
@@ -1,3 +1,3 @@
1
1
  module Invisible
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invisible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg