module-mixins 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c61833bbcf2dd6f75e5c56eb6d302628ff75060d
4
+ data.tar.gz: bc5557bc6e25fe38fa48b03fc42602e880b2231c
5
+ SHA512:
6
+ metadata.gz: 96d07aeb14eac0b83809516c8d2aae16db8f22658b53eab02af96989b7e8d284ed96b934a607ea9e4acaff18957ce403f679697a8801e62202758608049f00b4
7
+ data.tar.gz: 119c9d1b37bf15c6951e9699bf956bdc4260a63b9f39180a871036fb15dd8f4b72b416b9e2799157a9ae7afe0fffc772383d3ee1875f29999c44fa0309d787bc
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ pkg
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/**/*
4
+
5
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,34 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-11-04 09:40:51 -0500 using RuboCop version 0.34.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: AllowURI, URISchemes.
11
+ Metrics/LineLength:
12
+ Max: 87
13
+
14
+ # Offense count: 3
15
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
16
+ Style/ClassAndModuleChildren:
17
+ Exclude:
18
+ - 'lib/module/mixins/included.rb'
19
+ - 'lib/module/mixins/including.rb'
20
+ - 'lib/module/mixins/version.rb'
21
+
22
+ # Offense count: 3
23
+ # Configuration parameters: Exclude.
24
+ Style/Documentation:
25
+ Exclude:
26
+ - 'lib/module/mixins/included.rb'
27
+ - 'lib/module/mixins/including.rb'
28
+ - 'lib/module/mixins/version.rb'
29
+
30
+ # Offense count: 1
31
+ # Configuration parameters: Exclude.
32
+ Style/FileName:
33
+ Exclude:
34
+ - 'lib/module-mixins.rb'
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 2.2
3
+ - 2.1.1
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - jruby-19mode
@@ -0,0 +1,3 @@
1
+ ### 0.1.0 (2015/11/4)
2
+
3
+ * Initial public release with `Module::Mixins::Included` and `Module::Mixins::Including` - [@dblock](https://github.com/dblock).
@@ -0,0 +1,118 @@
1
+ Contributing to Module::Mixins
2
+ ==============================
3
+
4
+ Module::Mixins is work of [many contributors](https://github.com/dblock/module-mixins/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/dblock/module-mixins/pulls), [propose features, ask questions and discuss issues](https://github.com/dblock/module-mixins/issues).
5
+
6
+ #### Fork the Project
7
+
8
+ Fork the [project on Github](https://github.com/dblock/module-mixins) and check out your copy.
9
+
10
+ ```
11
+ git clone https://github.com/contributor/module-mixins.git
12
+ cd module-mixins
13
+ git remote add upstream https://github.com/dblock/module-mixins.git
14
+ ```
15
+
16
+ #### Create a Topic Branch
17
+
18
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
19
+
20
+ ```
21
+ git checkout master
22
+ git pull upstream master
23
+ git checkout -b my-feature-branch
24
+ ```
25
+
26
+ #### Bundle Install and Test
27
+
28
+ Ensure that you can build the project and run tests.
29
+
30
+ ```
31
+ bundle install
32
+ bundle exec rake
33
+ ```
34
+
35
+ #### Write Tests
36
+
37
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/module-mixins](spec/module-mixins).
38
+
39
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
40
+
41
+ #### Write Code
42
+
43
+ Implement your feature or bug fix.
44
+
45
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run `bundle exec rubocop` and fix any style issues highlighted.
46
+
47
+ Make sure that `bundle exec rake` completes without errors.
48
+
49
+ #### Write Documentation
50
+
51
+ Document any external behavior in the [README](README.md).
52
+
53
+ #### Update Changelog
54
+
55
+ Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account.
56
+
57
+ #### Commit Changes
58
+
59
+ Make sure git knows your name and email address:
60
+
61
+ ```
62
+ git config --global user.name "Your Name"
63
+ git config --global user.email "contributor@example.com"
64
+ ```
65
+
66
+ Writing good commit logs is important. A commit log should describe what changed and why.
67
+
68
+ ```
69
+ git add ...
70
+ git commit
71
+ ```
72
+
73
+ #### Push
74
+
75
+ ```
76
+ git push origin my-feature-branch
77
+ ```
78
+
79
+ #### Make a Pull Request
80
+
81
+ Go to https://github.com/contributor/module-mixins and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
82
+
83
+ #### Rebase
84
+
85
+ If you've been working on a change for a while, rebase with upstream/master.
86
+
87
+ ```
88
+ git fetch upstream
89
+ git rebase upstream/master
90
+ git push origin my-feature-branch -f
91
+ ```
92
+
93
+ #### Update CHANGELOG Again
94
+
95
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
96
+
97
+ ```
98
+ * [#123](https://github.com/dblock/module-mixins/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
99
+ ```
100
+
101
+ Amend your previous commit and force push the changes.
102
+
103
+ ```
104
+ git commit --amend
105
+ git push origin my-feature-branch -f
106
+ ```
107
+
108
+ #### Check on Your Pull Request
109
+
110
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
111
+
112
+ #### Be Patient
113
+
114
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
115
+
116
+ #### Thank You
117
+
118
+ Please do know that we really appreciate and value your time and work. We love you, really.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rspec'
7
+ end
8
+
9
+ group :development do
10
+ gem 'rake'
11
+ gem 'rubocop', '0.34.2'
12
+ end
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2015 Daniel Doubrovkine, Artsy and Contributors
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
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,84 @@
1
+ Module::Mixins
2
+ ==============
3
+
4
+ [![Gem Version](http://img.shields.io/gem/v/module-mixins.svg)](http://badge.fury.io/rb/module-mixins)
5
+ [![Build Status](http://img.shields.io/travis/dblock/module-mixins.svg)](https://travis-ci.org/dblock/module-mixins)
6
+ [![Dependency Status](https://gemnasium.com/dblock/module-mixins.svg)](https://gemnasium.com/dblock/module-mixins)
7
+ [![Code Climate](https://codeclimate.com/github/dblock/module-mixins.svg)](https://codeclimate.com/github/dblock/module-mixins)
8
+
9
+ Help with inspecting mixed-in Ruby modules.
10
+
11
+ ### Install
12
+
13
+ Add `module-mixins` to your Gemfile.
14
+
15
+ ```
16
+ gem 'module-mixins'
17
+ ```
18
+
19
+ ### Use
20
+
21
+ #### Find All Classes that Include a Module
22
+
23
+ In order to find all classes that include a module you would typically track those via the [Module.included](http://ruby-doc.org/core-2.2.0/Module.html#method-i-included) callback.
24
+
25
+ ```ruby
26
+ module MyModule
27
+ attr_accessor :classes_including
28
+
29
+ def included(base)
30
+ self.classes_including ||= []
31
+ self.classes_including << base
32
+ end
33
+ end
34
+ ```
35
+
36
+ This works well and is the behavior implemented in _module-mixins_ by [Module::Mixins::Included](lib/module/mixins/included.rb). You can `extend` your modules instead of duplicating code.
37
+
38
+ ```ruby
39
+ module MyModule
40
+ extend Module::Mixins::Included
41
+ end
42
+ ```
43
+
44
+ Ruby also provides a mechanism to enumerate all constants, which enables us to find mixed-in modules dynamically.
45
+
46
+ You can extend a module and call `classes_including` similarly.
47
+
48
+ ```ruby
49
+ module MyModule
50
+ extend Module::Mixins::Including
51
+ end
52
+ ```
53
+
54
+ You can also extend existing modules, which is quite powerful because you can apply it to modules you have not declared in your own code.
55
+
56
+ ```ruby
57
+ irb> Enumerable.extend Module::Mixins::Including
58
+ => Enumerable
59
+
60
+ irb> Enumerable.classes_including
61
+ => [Array, Hash, Struct, ..., Set, SortedSet]
62
+ ```
63
+
64
+ You can also use a module method without needing to mix-in another module.
65
+
66
+ ```ruby
67
+ irb> Module::Mixins::Including.classes_including(Comparable)
68
+ => [String, Symbol, Numeric, ..., Date, DateTime]
69
+ ```
70
+
71
+ ### References
72
+
73
+ * https://www.ruby-forum.com/topic/163430
74
+ * http://stackoverflow.com/questions/3917857/getting-a-list-of-classes-that-include-a-module
75
+
76
+ ### Contribute
77
+
78
+ See [CONTRIBUTING](CONTRIBUTING.md).
79
+
80
+ ### Copyright and License
81
+
82
+ Copyright Daniel Doubrovkine and Contributors, Artsy Inc., 2015
83
+
84
+ [MIT License](LICENSE.md)
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler/gem_tasks'
3
+
4
+ Bundler.setup :default, :development
5
+
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = FileList['spec/**/*_spec.rb']
11
+ end
12
+
13
+ require 'rubocop/rake_task'
14
+ RuboCop::RakeTask.new(:rubocop)
15
+
16
+ task default: [:rubocop, :spec]
@@ -0,0 +1 @@
1
+ require 'module/mixins'
@@ -0,0 +1,3 @@
1
+ require 'module/mixins/version'
2
+ require 'module/mixins/including'
3
+ require 'module/mixins/included'
@@ -0,0 +1,8 @@
1
+ module Module::Mixins::Included
2
+ attr_accessor :classes_including
3
+
4
+ def included(base)
5
+ self.classes_including ||= []
6
+ self.classes_including << base
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module Module::Mixins::Including
2
+ def classes_including
3
+ ::Module::Mixins::Including.classes_including self
4
+ end
5
+
6
+ def self.classes_including(klass)
7
+ ::Module.constants.map do |k|
8
+ next if k == k.upcase
9
+ c = Object.const_get k
10
+ next c if klass > c
11
+ end.compact
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Module::Mixins
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1 @@
1
+ require 'module-mixins'
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'module/mixins/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'module-mixins'
6
+ s.version = Module::Mixins::VERSION
7
+ s.authors = ['Daniel Doubrovkine']
8
+ s.email = 'dblock@dblock.org'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.required_rubygems_version = '>= 1.3.6'
11
+ s.files = `git ls-files`.split("\n")
12
+ s.require_paths = ['lib']
13
+ s.homepage = 'http://github.com/dblock/module-mixins'
14
+ s.licenses = ['MIT']
15
+ s.summary = 'Help with inspecting mixed-in Ruby modules.'
16
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Module::Mixins::Included do
4
+ context 'a class including a module' do
5
+ before do
6
+ @m = Module.new do
7
+ extend Module::Mixins::Included
8
+ end
9
+ @k = Class.new
10
+ @k.send :include, @m
11
+ end
12
+ it 'classes_including' do
13
+ expect(@m.classes_including).to eq [@k]
14
+ expect(@m.classes_including.first.new).to be_a_kind_of @k
15
+ end
16
+ context 'inherited' do
17
+ before do
18
+ @child = Class.new(@k)
19
+ end
20
+ it 'classes_including' do
21
+ expect(@m.classes_including).to eq [@k]
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Module::Mixins::Including do
4
+ context 'a class including a module' do
5
+ before do
6
+ @m = Module.new do
7
+ extend Module::Mixins::Including
8
+ end
9
+ @k = Class.new
10
+ @k.send :include, @m
11
+ Object.const_set "Class_#{SecureRandom.uuid.delete('-')}", @k
12
+ end
13
+ it 'classes_including' do
14
+ expect(@m.classes_including).to eq [@k]
15
+ expect(@m.classes_including.first.new).to be_a_kind_of @k
16
+ end
17
+ context 'inherited' do
18
+ before do
19
+ @child = Class.new(@k)
20
+ Object.const_set "Class_#{SecureRandom.uuid.delete('-')}", @child
21
+ end
22
+ it 'classes_including includes children' do
23
+ expect(@m.classes_including).to eq [@k, @child]
24
+ @child.send :include, @m
25
+ end
26
+ end
27
+ end
28
+ context 'Enumerable' do
29
+ before do
30
+ Enumerable.extend Module::Mixins::Including
31
+ end
32
+ it 'classes_including' do
33
+ expect(Enumerable.classes_including).to include Array
34
+ end
35
+ end
36
+ context 'module classes_including' do
37
+ it 'Enumerator' do
38
+ expect(Module::Mixins::Including.classes_including(Comparable)).to include String
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Module::Mixins do
4
+ it 'has a version' do
5
+ expect(Module::Mixins::VERSION.split('.').size).to eq 3
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'rubygems'
4
+ require 'rspec'
5
+
6
+ require 'module/mixins'
7
+
8
+ RSpec.configure(&:raise_errors_for_deprecations!)
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: module-mixins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Doubrovkine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: dblock@dblock.org
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - .gitignore
20
+ - .rspec
21
+ - .rubocop.yml
22
+ - .rubocop_todo.yml
23
+ - .travis.yml
24
+ - CHANGELOG.md
25
+ - CONTRIBUTING.md
26
+ - Gemfile
27
+ - LICENSE.md
28
+ - README.md
29
+ - Rakefile
30
+ - lib/module-mixins.rb
31
+ - lib/module/mixins.rb
32
+ - lib/module/mixins/included.rb
33
+ - lib/module/mixins/including.rb
34
+ - lib/module/mixins/version.rb
35
+ - lib/module_mixins.rb
36
+ - module-mixins.gemspec
37
+ - spec/module/mixins/included_spec.rb
38
+ - spec/module/mixins/including_spec.rb
39
+ - spec/module/mixins/version_spec.rb
40
+ - spec/spec_helper.rb
41
+ homepage: http://github.com/dblock/module-mixins
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: 1.3.6
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.4.5
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Help with inspecting mixed-in Ruby modules.
65
+ test_files: []