module-mixy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of module-mixy might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5acec850e92cf39d46076038ed0b9f3b3adb1bfde3af306bbc8d48985c4b8180
4
+ data.tar.gz: 93d9efb40cb952e0167267d18e86f4a8f9481e2c46b93a26a4dcdecb4d95f228
5
+ SHA512:
6
+ metadata.gz: 0da2d44df2b9e06de01d827625a2e2e429689f9778d677a2dd82510d3aac9f7a8b36862f579e8f46638167b4159b9288b4dcbdbc64ec13e61dcd8d4d169569f6
7
+ data.tar.gz: 118d916c21090d6131327e68bd5730387f608f70ff4c849f3659a4f792e7e27b632548857f4601cb03fa613d5395235be587bdd4d9f37756540feb9bb35de907
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ coverage.data
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # bundler
17
+ vendor/
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
23
+
24
+ # tmp-old
25
+ .old
26
+
27
+ # editor
28
+ *~
29
+ .redcar
30
+
31
+ # other
32
+ *.lock
33
+ *.bak
34
+ tool/
35
+ *\#*
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - ruby-head
5
+ - 2.6
6
+ - 2.5
7
+ - rbx-3
8
+ - jruby-head
9
+
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ - rvm: rbx-3
14
+ - rvm: jruby-head
15
+
16
+ before_install:
17
+ - gem install bundler
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --readme README.md --private lib/**/*.rb --exclude core_ext - MIT-LICENSE
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # coding: us-ascii
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT X11 License)
2
+
3
+ Copyright (c) 2012 Kenichi Kamiya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ module-mixy
2
+ ===========
3
+
4
+ `Module.mixy` is an imitation of `Module.mix`.
5
+
6
+ [![Build Status](https://secure.travis-ci.org/kachick/module-mixy.png)](http://travis-ci.org/kachick/module-mixy)
7
+ [![Gem Version](https://badge.fury.io/rb/module-mixy.png)](http://badge.fury.io/rb/module-mixy)
8
+
9
+ Features
10
+ --------
11
+
12
+ * Pure Ruby :)
13
+
14
+ Usage
15
+ -----
16
+
17
+ ### Overview
18
+
19
+ ```ruby
20
+ require 'module/mixy'
21
+
22
+ module Foo
23
+ def common
24
+ 'FOO :)'
25
+ end
26
+ end
27
+
28
+ module Bar
29
+ def common
30
+ 'bar :('
31
+ end
32
+ end
33
+
34
+ class FooBar
35
+ extend Module::Mixy
36
+ mixy Foo, :common => :foo_common
37
+ mixy Bar, :common => :bar_common
38
+ end
39
+
40
+ foobar = FooBar.new
41
+ p foobar.methods.grep(/common/) #=> [:bar_common, :foo_common]
42
+ p foobar.foo_common #=> "FOO :)"
43
+ p foobar.bar_common #=> "bar :("
44
+ ```
45
+
46
+ ### Be anywhere
47
+
48
+ ```ruby
49
+ require 'module/mixy/core_ext'
50
+ ```
51
+
52
+ Requirements
53
+ -------------
54
+
55
+ * [Ruby 2.5 or later](http://travis-ci.org/#!/kachick/module-mixy)
56
+
57
+ Install
58
+ -------
59
+
60
+ ```bash
61
+ $ gem install module-mixy
62
+ ```
63
+
64
+ Link
65
+ ----
66
+
67
+ * [Home](http://kachick.github.com/module-mixy)
68
+ * [code](https://github.com/kachick/module-mixy)
69
+ * [API](http://www.rubydoc.info/github/kachick/module-mixy)
70
+ * [issues](https://github.com/kachick/module-mixy/issues)
71
+ * [CI](http://travis-ci.org/#!/kachick/module-mixy)
72
+ * [gem](https://rubygems.org/gems/module-mixy)
73
+
74
+ License
75
+ --------
76
+
77
+ The MIT X11 License
78
+ Copyright (c) 2012 Kenichi Kamiya
79
+ See MIT-LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ # coding: us-ascii
3
+
4
+ require 'bundler/gem_tasks'
5
+
6
+ require 'rspec/core/rake_task'
7
+
8
+ task default: [:spec]
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.pattern = 'spec/**/*_spec.rb'
12
+ t.ruby_opts = %w[-w]
13
+ end
data/example/README.rb ADDED
@@ -0,0 +1,28 @@
1
+ # coding: us-ascii
2
+
3
+ $VERBOSE = true
4
+
5
+ require_relative '../lib/module/mixy'
6
+
7
+ module Foo
8
+ def common
9
+ 'FOO :)'
10
+ end
11
+ end
12
+
13
+ module Bar
14
+ def common
15
+ 'bar :('
16
+ end
17
+ end
18
+
19
+ class FooBar
20
+ extend Module::Mixy
21
+ mixy Foo, :common => :foo_common
22
+ mixy Bar, :common => :bar_common
23
+ end
24
+
25
+ foobar = FooBar.new
26
+ p foobar.methods.grep(/common/) #=> [:bar_common, :foo_common]
27
+ p foobar.foo_common #=> "FOO :)"
28
+ p foobar.bar_common #=> "bar :("
data/example/mix.rb ADDED
@@ -0,0 +1,27 @@
1
+ # coding: us-ascii
2
+
3
+ $VERBOSE = true
4
+
5
+ require_relative '../lib/module/mixy'
6
+
7
+ # @see http://www.rubyist.net/~matz/20101113.html
8
+
9
+ module American
10
+ attr_reader :address
11
+ end
12
+
13
+ module Japanese
14
+ attr_reader :address
15
+ end
16
+
17
+ class JapaneseAmerican
18
+ extend Module::Mixy
19
+ #mixy American
20
+ #mixy Japanese #=> [address] conflicts (Module::ConflictError)
21
+
22
+ mixy American, :address => :us_address
23
+ mixy Japanese, :address => :jp_address
24
+ end
25
+
26
+ p JapaneseAmerican.new.methods.grep(/address/) #=> [:jp_address, :us_address]
27
+
@@ -0,0 +1,71 @@
1
+ # coding: us-ascii
2
+ # Copyright (c) 2012 Kenichi Kamiya
3
+
4
+ class Module
5
+
6
+ module Mixy
7
+
8
+ class ConflictError < NameError; end
9
+
10
+ # @param feature_module [Module]
11
+ # @param aliases [Hash] origin<Symbol> => aliased<Symbol,nil,false>
12
+ # @return [self]
13
+ # if passes `aliases`, defines the renamed methods.
14
+ # if aliases are not given, behaves as `include` with preventing to conflict.
15
+ def mixy(feature_module, aliases={})
16
+ specific_module = specific_module_from feature_module, aliases
17
+ check_conflicts specific_module
18
+
19
+ include specific_module
20
+ self
21
+ end
22
+
23
+ module_function
24
+
25
+ # @param mod [Module]
26
+ # @return [Array<Symbol>]
27
+ def methods_from(mod)
28
+ mod.instance_methods(true) | mod.private_instance_methods(true)
29
+ end
30
+
31
+ private
32
+
33
+ # @return [Module]
34
+ def specific_module_from(feature_module, aliases)
35
+ specific_module = feature_module.dup
36
+ keep_features = methods_from self
37
+
38
+ specific_module.module_eval do
39
+ features = instance_methods(false) | private_instance_methods(false)
40
+ ignores = Mixy.methods_from(specific_module) - (keep_features | features | aliases.keys)
41
+ undef_method(*ignores)
42
+
43
+ aliases.each_pair do |origin, aliased|
44
+ alias_method aliased, origin if aliased
45
+
46
+ if keep_features.include? origin
47
+ remove_method origin
48
+ else
49
+ undef_method origin
50
+ end
51
+ end
52
+ end
53
+
54
+ specific_module
55
+ end
56
+
57
+ # @return [nil]
58
+ def check_conflicts(specific_module)
59
+ conflicts = methods_from(self) & methods_from(specific_module)
60
+ conflicts.each do |conflict|
61
+ err = ConflictError.new \
62
+ "#{conflict} is a conflict name - all coflicts: [#{conflicts.join(', ')}]", conflict
63
+ raise err
64
+ end
65
+
66
+ nil
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,9 @@
1
+ # coding: us-ascii
2
+
3
+ require_relative '../mixy'
4
+
5
+ class Module
6
+
7
+ include Mixy
8
+
9
+ end
@@ -0,0 +1,30 @@
1
+ # coding: us-ascii
2
+
3
+ Gem::Specification.new do |gem|
4
+ # specific
5
+
6
+ gem.name = 'module-mixy'
7
+ gem.description = %q{Module.mixy is an imitation of Module.mix.}
8
+ gem.summary = gem.description.dup
9
+ gem.license = 'MIT'
10
+ gem.version = '0.1.0'
11
+
12
+ gem.add_development_dependency 'rspec', '>= 3.8', '< 4'
13
+ gem.add_development_dependency 'yard', '>= 0.9.20', '< 2'
14
+ gem.add_development_dependency 'rake', '>= 10', '< 20'
15
+ gem.add_development_dependency 'bundler', '>= 2', '< 3'
16
+
17
+ if RUBY_ENGINE == 'rbx'
18
+ gem.add_dependency 'rubysl', '~> 2.1'
19
+ end
20
+
21
+ # common
22
+
23
+ gem.homepage = "http://kachick.github.com/#{gem.name}"
24
+ gem.authors = ['Kenichi Kamiya']
25
+ gem.email = ['kachick1+ruby@gmail.com']
26
+ gem.files = `git ls-files`.split($\)
27
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
28
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
29
+ gem.require_paths = ['lib']
30
+ end
@@ -0,0 +1,89 @@
1
+ # coding: us-ascii
2
+
3
+ require_relative 'helper'
4
+
5
+ describe Module::Mixy do
6
+ before(:each) do
7
+ @class = Class.new do
8
+ extend Module::Mixy
9
+ end
10
+ end
11
+
12
+ describe "#mixy" do
13
+ it "is a public method" do
14
+ expect(@class.public_methods).to include(:mixy)
15
+ end
16
+
17
+ it "returns self" do
18
+ expect(@class.mixy HasPublicAndPrivate).to equal(@class)
19
+ end
20
+
21
+ it "extends self with the features" do
22
+ @class.mixy HasPublicAndPrivate
23
+ expect(@class.public_instance_methods).to include(:public_func)
24
+ expect(@class.new.public_func).to eq(:ret_public_func_on_has_public_and_private)
25
+ expect(@class.private_instance_methods).to include(:private_func)
26
+ expect(@class.new.__send__(:private_func)).to eq(:ret_private_func_on_has_public_and_private)
27
+ end
28
+
29
+ it "does not extend with ancestors of the module" do
30
+ @class.mixy HasPublicAndPrivate
31
+ instance = @class.new
32
+ expect { instance.__send__(:not_want_public_func) }.to raise_error(NoMethodError)
33
+ end
34
+
35
+ context "when the module has same method-name" do
36
+ before(:each) do
37
+ @class.mixy HasPublicAndPrivate
38
+ end
39
+
40
+ context "the method visibility is public" do
41
+ it "raises a ConflictError and it is set with #name" do
42
+ expect do
43
+ @class.mixy HasPublic
44
+ end.to(raise_error(Module::Mixy::ConflictError) do |err|
45
+ expect(err.name).to eq(:public_func)
46
+ end)
47
+ end
48
+
49
+ it "extends self with aliased name" do
50
+ @class.mixy HasPublic, :public_func => :public_func_aliased
51
+ expect(@class.public_instance_methods).to include(:public_func_aliased)
52
+ expect(@class.new.public_func_aliased).to eq(:ret_public_func_on_has_public)
53
+ expect(@class.new.public_func).to eq(:ret_public_func_on_has_public_and_private)
54
+ end
55
+
56
+ context "when the aliased name is a falsy value" do
57
+ it "ignores origin name and does not define the aliased name" do
58
+ before = @class.public_instance_methods
59
+ @class.mixy HasPublic, :public_func => nil
60
+ expect(@class.public_instance_methods).to eq(before)
61
+ end
62
+ end
63
+ end
64
+
65
+ context "the method visibility is private" do
66
+ it "raises a ConflictError and it is set with #name" do
67
+ expect do
68
+ @class.mixy HasPrivate
69
+ end.to(raise_error(Module::Mixy::ConflictError) do |err|
70
+ expect(err.name).to eq(:private_func)
71
+ end)
72
+ end
73
+
74
+ it "extends self with aliased name" do
75
+ @class.mixy HasPrivate, :private_func => :private_func_aliased
76
+ expect(@class.private_instance_methods).to include(:private_func_aliased)
77
+ expect(@class.new.__send__(:private_func_aliased)).to eq(:ret_private_func_on_has_private)
78
+ expect(@class.new.__send__(:private_func)).to eq(:ret_private_func_on_has_public_and_private)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ describe Module::Mixy::ConflictError do
85
+ it "is a subclass of NameError" do
86
+ expect(Module::Mixy::ConflictError.superclass).to equal(NameError)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,11 @@
1
+ # coding: us-ascii
2
+
3
+ require_relative 'helper'
4
+ require_relative '../lib/module/mixy/core_ext'
5
+
6
+ describe Module::Mixy do
7
+ it "can call #mixy on any modules" do
8
+ mod = Module.new
9
+ expect(mod.mixy Module.new).to equal(mod)
10
+ end
11
+ end
data/spec/fixtures.rb ADDED
@@ -0,0 +1,41 @@
1
+ # coding: us-ascii
2
+
3
+ module Module::Mixy::RspecHelpers
4
+ Ancestor = Module.new do
5
+ def public_func
6
+ :ret_public_func_on_ancestor
7
+ end
8
+
9
+ def not_want_public_func
10
+ :ret_not_want_public_func_on_ancestor
11
+ end
12
+ end
13
+
14
+ HasPublicAndPrivate = Module.new do
15
+ include Ancestor
16
+
17
+ def public_func
18
+ :ret_public_func_on_has_public_and_private
19
+ end
20
+
21
+ private
22
+
23
+ def private_func
24
+ :ret_private_func_on_has_public_and_private
25
+ end
26
+ end
27
+
28
+ HasPublic = Module.new do
29
+ def public_func
30
+ :ret_public_func_on_has_public
31
+ end
32
+ end
33
+
34
+ HasPrivate = Module.new do
35
+ private
36
+
37
+ def private_func
38
+ :ret_private_func_on_has_private
39
+ end
40
+ end
41
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,12 @@
1
+ # coding: us-ascii
2
+
3
+ require 'rspec'
4
+
5
+ require_relative '../lib/module/mixy'
6
+ require_relative 'fixtures'
7
+
8
+ RSpec.configure do |configuration|
9
+ configuration.include Module::Mixy::RspecHelpers
10
+ end
11
+
12
+ include Module::Mixy::RspecHelpers
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: module-mixy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenichi Kamiya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.8'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.8'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
33
+ - !ruby/object:Gem::Dependency
34
+ name: yard
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.9.20
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '2'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.9.20
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '2'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '10'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '20'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '10'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '20'
73
+ - !ruby/object:Gem::Dependency
74
+ name: bundler
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '2'
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '2'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '3'
93
+ description: Module.mixy is an imitation of Module.mix.
94
+ email:
95
+ - kachick1+ruby@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - ".gitignore"
101
+ - ".travis.yml"
102
+ - ".yardopts"
103
+ - Gemfile
104
+ - MIT-LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - example/README.rb
108
+ - example/mix.rb
109
+ - lib/module/mixy.rb
110
+ - lib/module/mixy/core_ext.rb
111
+ - module-mixy.gemspec
112
+ - spec/basic_spec.rb
113
+ - spec/core_ext_spec.rb
114
+ - spec/fixtures.rb
115
+ - spec/helper.rb
116
+ homepage: http://kachick.github.com/module-mixy
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.7.6
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Module.mixy is an imitation of Module.mix.
140
+ test_files:
141
+ - spec/basic_spec.rb
142
+ - spec/core_ext_spec.rb
143
+ - spec/fixtures.rb
144
+ - spec/helper.rb