invisible 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 71eaaea3d7717f03a1c2cc31d99041521b86e5ac65d8cdd98c2a89cdb2b7f391
4
+ data.tar.gz: 84aab41ab090a0cf4a0e26c9fa7372cc4e021f06eb11e508c580ef7b7ed1d525
5
+ SHA512:
6
+ metadata.gz: 9c3fb7f7b396583c6c23d90902750b2caccc5956fe8a740ce90f19c1342b703d6b9419f3b5df009074a39df3195c4b347a7b70b80fcd949c0a9814ccc8a38f52
7
+ data.tar.gz: 3e81b037145ec1c7b2335317972b6f9f50a42ffecd7ab84591578d9c4126ee0b33c47ab1273e3180a872ed2aee92bc101c09b26449b9bac7fa0899db87b65619
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in invisible.gemspec
4
+ gemspec
5
+
6
+ platforms :ruby do
7
+ gem 'guard-rspec'
8
+ gem 'pry-byebug'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ invisible (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.0.1)
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ ffi (1.11.1)
13
+ formatador (0.2.5)
14
+ guard (2.15.1)
15
+ formatador (>= 0.2.4)
16
+ listen (>= 2.7, < 4.0)
17
+ lumberjack (>= 1.0.12, < 2.0)
18
+ nenv (~> 0.1)
19
+ notiffany (~> 0.0)
20
+ pry (>= 0.9.12)
21
+ shellany (~> 0.0)
22
+ thor (>= 0.18.1)
23
+ guard-compat (1.2.1)
24
+ guard-rspec (4.7.3)
25
+ guard (~> 2.1)
26
+ guard-compat (~> 1.1)
27
+ rspec (>= 2.99.0, < 4.0)
28
+ listen (3.2.0)
29
+ rb-fsevent (~> 0.10, >= 0.10.3)
30
+ rb-inotify (~> 0.9, >= 0.9.10)
31
+ lumberjack (1.0.13)
32
+ method_source (0.9.2)
33
+ nenv (0.3.0)
34
+ notiffany (0.1.3)
35
+ nenv (~> 0.1)
36
+ shellany (~> 0.0)
37
+ pry (0.12.2)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ pry-byebug (3.7.0)
41
+ byebug (~> 11.0)
42
+ pry (~> 0.10)
43
+ rake (10.5.0)
44
+ rb-fsevent (0.10.3)
45
+ rb-inotify (0.10.0)
46
+ ffi (~> 1.0)
47
+ rspec (3.9.0)
48
+ rspec-core (~> 3.9.0)
49
+ rspec-expectations (~> 3.9.0)
50
+ rspec-mocks (~> 3.9.0)
51
+ rspec-core (3.9.0)
52
+ rspec-support (~> 3.9.0)
53
+ rspec-expectations (3.9.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.9.0)
56
+ rspec-mocks (3.9.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.9.0)
59
+ rspec-support (3.9.0)
60
+ shellany (0.0.1)
61
+ thor (0.20.3)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ guard-rspec
68
+ invisible!
69
+ pry-byebug
70
+ rake (~> 10.0)
71
+ rspec (~> 3.0)
72
+
73
+ BUNDLED WITH
74
+ 2.0.2
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Chris Salzberg
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,74 @@
1
+ # Invisible
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.
4
+
5
+ ## Usage
6
+
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!
8
+
9
+ Suppose this is the class we are overriding:
10
+
11
+ ```ruby
12
+ class Base
13
+ def public_method
14
+ 'public'
15
+ end
16
+
17
+ protected
18
+
19
+ def protected_method
20
+ 'protected'
21
+ end
22
+
23
+ private
24
+
25
+ def private_method
26
+ 'private'
27
+ end
28
+ end
29
+ ```
30
+
31
+ We don't want to care about whether the methods are private or whatever. So we define our module like so:
32
+
33
+ ```ruby
34
+ module Foo
35
+ extend Invisible
36
+
37
+ def public_method
38
+ super + 'foo'
39
+ end
40
+
41
+ def protected_method
42
+ super + 'foo'
43
+ end
44
+
45
+ def private_method
46
+ super + 'foo'
47
+ end
48
+ end
49
+ ```
50
+
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.
52
+
53
+ ```ruby
54
+ class MyClass < Base
55
+ include Foo
56
+ end
57
+
58
+ instance = MyClass.new
59
+
60
+ instance.public_method_defined?(:public_method) #=> true
61
+ instance.public_method #=> 'publicfoo'
62
+
63
+ instance.protected_method_defined?(:protected_method) #=> true
64
+ instance.protected_method # raises NoMethodError
65
+ instance.send(:protected_method) #=> 'protectedfoo'
66
+
67
+ instance.private_method_defined?(:private_method) #=> true
68
+ instance.private_method # raises NoMethodError
69
+ instance.send(:private_method) #=> 'privatefoo'
70
+ ```
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/invisible.rb ADDED
@@ -0,0 +1,71 @@
1
+ require "invisible/version"
2
+
3
+ module Invisible
4
+ =begin
5
+
6
+ Extend any module with +Invisible+ and any methods the module overrides will
7
+ maintain their original visibility.
8
+
9
+ @example
10
+ class Base
11
+ def public_method
12
+ 'public'
13
+ end
14
+
15
+ protected
16
+
17
+ def protected_method
18
+ 'protected'
19
+ end
20
+
21
+ private
22
+
23
+ def private_method
24
+ 'private'
25
+ end
26
+ end
27
+
28
+ module Foo
29
+ extend Invisible
30
+
31
+ def public_method
32
+ super + 'foo'
33
+ end
34
+
35
+ def protected_method
36
+ super + 'foo'
37
+ end
38
+
39
+ def private_method
40
+ super + 'foo'
41
+ end
42
+ end
43
+
44
+ class MyClass < Base
45
+ include Foo
46
+ end
47
+
48
+ instance = MyClass.new
49
+
50
+ instance.public_method_defined?(:public_method) #=> true
51
+ instance.public_method #=> 'publicfoo'
52
+
53
+ instance.protected_method_defined?(:protected_method) #=> true
54
+ instance.protected_method # raises NoMethodError
55
+ instance.send(:protected_method) #=> 'protectedfoo'
56
+
57
+ instance.private_method_defined?(:private_method) #=> true
58
+ instance.private_method # raises NoMethodError
59
+ instance.send(:private_method) #=> 'privatefoo'
60
+
61
+ =end
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 }
65
+
66
+ super
67
+
68
+ private_methods.each { |method_name| base.class_eval { private method_name } }
69
+ protected_methods.each { |method_name| base.class_eval { protected method_name } }
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module Invisible
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: invisible
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Salzberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ description:
42
+ email:
43
+ - chris@dejimata.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - Guardfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/invisible.rb
55
+ - lib/invisible/version.rb
56
+ homepage: https://github.com/shioyama/invisible
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://github.com/shioyama/invisible
61
+ source_code_uri: https://github.com/shioyama/invisible
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.7.6.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Override methods while maintaining their original visibility.
82
+ test_files: []