invisible 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71eaaea3d7717f03a1c2cc31d99041521b86e5ac65d8cdd98c2a89cdb2b7f391
4
- data.tar.gz: 84aab41ab090a0cf4a0e26c9fa7372cc4e021f06eb11e508c580ef7b7ed1d525
3
+ metadata.gz: ec6e3dc7bce460129f162a4d86d209e6bcb60465cbed9a27cdd72be8ab39a153
4
+ data.tar.gz: bb55e63585517a844219039697c213e419d408a6d38faee9edcd9fd164824d52
5
5
  SHA512:
6
- metadata.gz: 9c3fb7f7b396583c6c23d90902750b2caccc5956fe8a740ce90f19c1342b703d6b9419f3b5df009074a39df3195c4b347a7b70b80fcd949c0a9814ccc8a38f52
7
- data.tar.gz: 3e81b037145ec1c7b2335317972b6f9f50a42ffecd7ab84591578d9c4126ee0b33c47ab1273e3180a872ed2aee92bc101c09b26449b9bac7fa0899db87b65619
6
+ metadata.gz: c7c27b7f1ac6b9f10f0c62129fa61361c526f07a780263dc5e0d2b64579baa025542002354094b405ad3913dad07aba26809f188619ecf307a3d6cdbe962e52f
7
+ data.tar.gz: a0fc24dd164097118d0a214e5004ec84d26ae5686ad5cd465f5b00ccb2911f9232890550e7d8b5d4c6e16404f0a64d7080302439ed0f50f36f365cf8a0b3d84b
data/README.md CHANGED
@@ -1,10 +1,18 @@
1
1
  # Invisible
2
2
 
3
- Invisible allows you to quickly define method overrides in a module without worrying about messing up their original visibility. It does this in less than ten lines of code.
3
+ [![Gem Version](https://badge.fury.io/rb/invisible.svg)][gem]
4
+ [![Build Status](https://travis-ci.com/shioyama/invisible.svg?branch=master)][travis]
5
+
6
+ [gem]: https://rubygems.org/gems/invisible
7
+ [travis]: https://travis-ci.com/shioyama/invisible
8
+
9
+ Public? Private? Protected? Who cares! I just want to monkey patch that shit!
10
+
11
+ No fear: Invisible has your back! This little ten-line gem does away with the problem of maintaining original method visibility, so you can get on with your monkey-patching mayhem.
4
12
 
5
13
  ## Usage
6
14
 
7
- Suppose you are defining a module which will override a bunch of methods from some class (or module). Simply `extend Invisible` and you can ignore checking whether those methods are public, protected or private -- Invisible will take care of that for you!
15
+ Suppose you are defining a module which will override a bunch of methods from some class (or module). Simply `extend Invisible` and you can ignore checking whether those methods are public, protected or private -- Invisible will take care of that for you.
8
16
 
9
17
  Suppose this is the class we are overriding:
10
18
 
@@ -48,7 +56,7 @@ module Foo
48
56
  end
49
57
  ```
50
58
 
51
- Normally, without Invisible, we would have just made methods that were previously `private` become `public`. But Invisible checks the original visibility and ensures that when the module is included, methods which were originally private or protected stay that way.
59
+ Normally, without Invisible, we would have just made methods that were previously `private` or `protected` become `public`. But Invisible checks the original visibility and ensures that when the module is included, methods which were originally private or protected stay that way.
52
60
 
53
61
  ```ruby
54
62
  class MyClass < Base
@@ -69,6 +77,23 @@ instance.private_method # raises NoMethodError
69
77
  instance.send(:private_method) #=> 'privatefoo'
70
78
  ```
71
79
 
80
+ Also works with `prepend`:
81
+
82
+ ```ruby
83
+ class MyClass < Base
84
+ prepend Foo
85
+
86
+ private
87
+ def private_method
88
+ super + 'bar'
89
+ end
90
+ end
91
+
92
+ instance = MyClass.new
93
+ instance.private_method # raises NoMethodError
94
+ instance.send(:private_method) #=> 'privatebarfoo'
95
+ ```
96
+
72
97
  ## License
73
98
 
74
99
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,9 @@
1
+ # Invisible Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ * Add support for `prepend`. ([#2](https://github.com/shioyama/invisible/pull/2))
6
+
7
+ ## 0.1.0
8
+
9
+ * Support for `include`.
@@ -1,3 +1,3 @@
1
1
  module Invisible
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/invisible.rb CHANGED
@@ -60,12 +60,29 @@ maintain their original visibility.
60
60
 
61
61
  =end
62
62
  def append_features(base)
63
- private_methods = instance_methods.select { |m| base.private_method_defined? m }
64
- protected_methods = instance_methods.select { |m| base.protected_method_defined? m }
63
+ sync_visibility(base) { super }
64
+ end
65
+
66
+ def prepend_features(base)
67
+ return super if synced
68
+
69
+ sync_visibility(base, mod = dup)
70
+ mod.synced = true
71
+ base.prepend mod
72
+ end
73
+
74
+ protected
75
+ attr_accessor :synced
76
+
77
+ private
78
+
79
+ def sync_visibility(source, target = source)
80
+ private_methods = instance_methods.select { |m| source.private_method_defined? m }
81
+ protected_methods = instance_methods.select { |m| source.protected_method_defined? m }
65
82
 
66
- super
83
+ yield if block_given?
67
84
 
68
- private_methods.each { |method_name| base.class_eval { private method_name } }
69
- protected_methods.each { |method_name| base.class_eval { protected method_name } }
85
+ private_methods.each { |method_name| target.class_eval { private method_name } }
86
+ protected_methods.each { |method_name| target.class_eval { protected method_name } }
70
87
  end
71
88
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
@@ -52,6 +52,7 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - lib/invisible.rb
55
+ - lib/invisible/CHANGELOG.md
55
56
  - lib/invisible/version.rb
56
57
  homepage: https://github.com/shioyama/invisible
57
58
  licenses:
@@ -74,8 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  requirements: []
77
- rubyforge_project:
78
- rubygems_version: 2.7.6.2
78
+ rubygems_version: 3.0.6
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Override methods while maintaining their original visibility.