include_with_respect 1.0.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: d31e3eb1f1ebb2467b8a102c57e79564fb73d4ca41e8c5ace83a4c2d96ee76d7
4
+ data.tar.gz: 1b5634ceba4dc95b0b07ed91f7b2f842b9c28675cc89481bc98372a46b71cbc6
5
+ SHA512:
6
+ metadata.gz: cc70f6f73049bfbf74b9a946b437655a27f14621a5171651fadc3f09a3e7f45e1fdb5f1ac26fc8654b689bf942530a289e993a12c0b7c0fbc730e7a6ee0045a5
7
+ data.tar.gz: 90640492a0a096cd44e09ba7e832fd1eeeb9da9e73424ae6e5f2c1da509c0061fc5d2c5b62da9c5409b7a9f8758ba4df066146453fed0c4a613096982dc2736f
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /*.gem
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.5
data/.travis.yml ADDED
@@ -0,0 +1,38 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache:
4
+ bundler: true
5
+ env:
6
+ global:
7
+ CC_TEST_REPORTER_ID=da3f62293bf581a89f1401a183a4ee30e43c2f150913635992062367771ddfd9
8
+ before_install:
9
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
10
+ - chmod +x ./cc-test-reporter
11
+ - ./cc-test-reporter before-build
12
+ - gem install bundler:1.17.3
13
+ install:
14
+ - bundle install --path=${BUNDLE_PATH:-vendor/bundle} # Install ruby gems
15
+ script:
16
+ # - bundle exec rubocop -DESP # linting
17
+ - bundle exec rake # specs
18
+
19
+ # Pipe the coverage data to Code Climate
20
+ after_script:
21
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
22
+
23
+ jobs:
24
+ include:
25
+ - rvm: ruby-2.0.0-p648
26
+ gemfile: gemfiles/ruby_2.0.gemfile
27
+ - rvm: ruby-2.1.10
28
+ gemfile: gemfiles/ruby_2.1.gemfile
29
+ - rvm: ruby-2.2.10
30
+ gemfile: gemfiles/ruby_2.2.gemfile
31
+ - rvm: ruby-2.3.8
32
+ gemfile: gemfiles/ruby_2.3.gemfile
33
+ - rvm: ruby-2.4.9
34
+ gemfile: gemfiles/ruby_2.4.gemfile
35
+ - rvm: ruby-2.5.7
36
+ gemfile: gemfiles/ruby_2.5.gemfile
37
+ - rvm: ruby-2.6.5
38
+ gemfile: gemfiles/ruby_2.6.gemfile
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at peter.boling@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in include_with_respect.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Peter Boling
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # IncludeWithRespect
2
+
3
+ *Find out if your include/extend hooks are misbehaving!*
4
+
5
+ ## Why did I make this gem?
6
+
7
+ Modules have hooks on `include` and `extend`, among others. These will run every time a module is included or extended into another module or class. If the hooks should only run once, (think shared state), then running them multiple times can cause difficult to trace bugs. This gem allows developers to trace modules that are re-included multiple times into other objects.
8
+
9
+ | Project | IncludeWithRespect |
10
+ |------------------------ | ----------------------- |
11
+ | gem name | [include_with_respect][rubygems] |
12
+ | license | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][mit] |
13
+ | download rank | [![Downloads Today](https://img.shields.io/gem/rd/include_with_respect.svg)](https://github.com/pboling/include_with_respect) |
14
+ | version | [![Version](https://img.shields.io/gem/v/include_with_respect.svg)][rubygems] |
15
+ | dependencies | [![Depfu](https://badges.depfu.com/badges/7ab03542cae3755d64038f7b3e7af53e/count.svg)](https://depfu.com/github/pboling/include_with_respect?project_id=10361) |
16
+ | continuous integration | [![Build Status](https://travis-ci.org/pboling/include_with_respect.svg?branch=master)](https://travis-ci.org/pboling/include_with_respect) |
17
+ | test coverage | [![Test Coverage](https://api.codeclimate.com/v1/badges/604a8f3a996c008cb2ae/test_coverage)](https://codeclimate.com/github/pboling/include_with_respect/test_coverage) |
18
+ | maintainability | [![Maintainability](https://api.codeclimate.com/v1/badges/604a8f3a996c008cb2ae/maintainability)](https://codeclimate.com/github/pboling/include_with_respect/maintainability) |
19
+ | code triage | [![Open Source Helpers](https://www.codetriage.com/pboling/include_with_respect/badges/users.svg)](https://www.codetriage.com/pboling/include_with_respect) |
20
+ | FOSSA Licenses | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fpboling%2Finclude_with_respect.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fpboling%2Finclude_with_respect?ref=badge_shield) |
21
+ | homepage | [on Github.com][homepage], [on Railsbling.com][blogpage] |
22
+ | documentation | [on RDoc.info][documentation] |
23
+ | Spread ~♡ⓛⓞⓥⓔ♡~ | [🌍 🌎 🌏][about-me], [🍚][crowdrise], [👼][angel-list], [🐛][topcoder], [:shipit:][coderwall], [![Tweet Peter][twitter-followers]][twitter] |
24
+
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ ```ruby
31
+ gem 'include_with_respect'
32
+ ```
33
+
34
+ And then execute:
35
+
36
+ $ bundle
37
+
38
+ Or install it yourself as:
39
+
40
+ $ gem install include_with_respect
41
+
42
+ ## Usage
43
+
44
+ ### Example Use with `ActiveSupport::Concern`
45
+
46
+ ```ruby
47
+ module MyConcern
48
+ extend ActiveSupport::Concern
49
+ included do
50
+ include IncludeWithRespect::ConcernWithRespect
51
+ include SomeOtherConcern
52
+ end
53
+ end
54
+ ```
55
+
56
+ Then if `MyConcern` is included somewhere that also includes `SomeOtherConcern` two things will happen that normally do not:
57
+ 1. a warning will be printed (via `puts`)
58
+ 2. the duplicate inclusion will be skipped (meaning the hooks will not run again)
59
+ - This is a major change in the behavior of including modules, but normally hooks running multiple times is not desired, or intended, which is why this gem exists!
60
+
61
+ ## Development
62
+
63
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+
65
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pboling/include_with_respect.
70
+
71
+ Create an issue and tell me about it, or fix it yo'sef.
72
+
73
+ 1. Fork it
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
78
+ 6. Create new Pull Request
79
+
80
+ ## Versioning
81
+
82
+ This library aims to adhere to [Semantic Versioning 2.0.0][semver].
83
+ Violations of this scheme should be reported as bugs. Specifically,
84
+ if a minor or patch version is released that breaks backward
85
+ compatibility, a new version should be immediately released that
86
+ restores compatibility. Breaking changes to the public API will
87
+ only be introduced with new major versions.
88
+
89
+ As a result of this policy, you can (and should) specify a
90
+ dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
91
+
92
+ For example:
93
+
94
+ spec.add_dependency 'include_with_respect', '~> 0.0'
95
+
96
+ ## Legal
97
+
98
+ * [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
99
+ * Copyright (c) 2019 [Peter H. Boling][peterboling] of [Rails Bling][railsbling]
100
+
101
+ [semver]: http://semver.org/
102
+ [pvc]: http://docs.rubygems.org/read/chapter/16#page74
103
+ [railsbling]: http://www.railsbling.com
104
+ [peterboling]: http://www.peterboling.com
105
+ [coderwall]: http://coderwall.com/pboling
106
+ [documentation]: http://rdoc.info/github/pboling/gem_bench/frames
107
+ [homepage]: https://github.com/pboling/gem_bench
108
+ [mit]: https://opensource.org/licenses/MIT
109
+ [rubygems]: https://rubygems.org/gems/include_with_respect
110
+ [about-me]: https://about.me/peter.boling
111
+ [crowdrise]: https://www.crowdrise.com/helprefugeeswithhopefortomorrowliberia/fundraiser/peterboling
112
+ [angel-list]: https://angel.co/peter-boling
113
+ [topcoder]: https://www.topcoder.com/members/pboling/
114
+ [coderwall]: http://coderwall.com/pboling
115
+ [twitter-followers]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow
116
+ [twitter]: http://twitter.com/galtzo
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/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'include_with_respect'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler", "~> 1.17.3"
6
+ gem "byebug", "9.0.6"
7
+ gem "pry-byebug", "3.4.3"
8
+ gem "rubocop", "0.50.0"
9
+ gem "rubocop-rspec", "1.5.1"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler", "~> 1.17.3"
6
+ gem "byebug", "9.0.6"
7
+ gem "pry-byebug", "3.4.3"
8
+ gem "rubocop", "0.57.2"
9
+ gem "rubocop-rspec", "1.27.0"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler", "~> 1.17.3"
6
+ gem "byebug", "10.0.2"
7
+ gem "pry-byebug", "3.6.0"
8
+ gem "rubocop", "0.68.1"
9
+ gem "rubocop-rspec", "1.32.0"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler", "~> 1.17.3"
6
+ gem "byebug", "11.0.1"
7
+ gem "pry-byebug", "3.7.0"
8
+ gem "rubocop", "0.77.0"
9
+ gem "rubocop-rspec", "1.37.1"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler", "~> 1.17.3"
6
+ gem "byebug", "11.0.1"
7
+ gem "pry-byebug", "3.7.0"
8
+ gem "rubocop", "0.77.0"
9
+ gem "rubocop-rspec", "1.37.1"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler"
6
+ gem "byebug"
7
+ gem "pry-byebug"
8
+ gem "rubocop"
9
+ gem "rubocop-rspec"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler"
6
+ gem "byebug"
7
+ gem "pry-byebug"
8
+ gem "rubocop"
9
+ gem "rubocop-rspec"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,40 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'include_with_respect/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'include_with_respect'
7
+ spec.version = IncludeWithRespect::VERSION
8
+ spec.authors = ['Peter Boling']
9
+ spec.email = ['peter.boling@gmail.com']
10
+
11
+ spec.summary = 'Untangle dependency trees'
12
+ spec.homepage = 'http://github.com/pboling/include_with_respect'
13
+
14
+ spec.metadata['homepage_uri'] = spec.homepage
15
+ spec.metadata['source_code_uri'] = 'http://github.com/pboling/include_with_respect'
16
+ spec.metadata['changelog_uri'] = 'http://github.com/pboling/include_with_respect/blob/master/CHANGELOG'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_development_dependency 'appraisal'
28
+ spec.add_development_dependency 'byebug'
29
+ spec.add_development_dependency 'bundler'
30
+ spec.add_development_dependency 'gem-release', '~> 2.0'
31
+ spec.add_development_dependency 'pry-byebug'
32
+ spec.add_development_dependency 'rake'
33
+ spec.add_development_dependency 'rspec'
34
+ spec.add_development_dependency 'rspec-block_is_expected'
35
+ spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'rubocop-rspec'
37
+ spec.add_development_dependency 'silent_stream'
38
+ spec.add_development_dependency 'simplecov'
39
+ spec.add_development_dependency 'wwtd'
40
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'include_with_respect/version'
4
+ require 'include_with_respect/configuration'
5
+
6
+ # How to automatically inject into ActiveSupport::Concern,
7
+ # or other module dependency trees?
8
+ # Refer to inline documentation in each file.
9
+ require 'include_with_respect/module_with_respect'
10
+ require 'include_with_respect/concern_with_respect' if defined?(ActiveSupport)
11
+
12
+ # [Sometimes] We should respect our ancestors.
13
+ # If you swap `include` for `include_with_respect`, when a module is already among our ancestors does not re-include it.
14
+ # Why?
15
+ # Some modules have side effects on the `included` hook which can be problematic if they run more than once.
16
+ # Additionally, including a module multiple times will override the original include,
17
+ # but in a messy way, with potentially dangerous side effects and shared state.
18
+ module IncludeWithRespect
19
+ class Error < StandardError; end
20
+
21
+ def include_with_respect(receiver, module1, *smth)
22
+ @skip_include = false
23
+ have_respect('included', receiver, module1, *smth) if receiver.include?(module1)
24
+
25
+ receiver.send(:include_without_respect, module1, *smth) unless @skip_include
26
+ end
27
+ module_function :include_with_respect
28
+
29
+ def extend_with_respect(receiver, module1, *smth)
30
+ @skip_include = false
31
+ have_respect('extended', receiver, module1, skip, *smth) if receiver.singleton_class.include?(module1)
32
+
33
+ receiver.send(:extend_without_respect, module1, *smth) unless @skip_include
34
+ end
35
+ module_function :extend_with_respect
36
+
37
+ # For single statement global config in an initializer
38
+ # e.g. IncludeWithRespect.configuration.level = :error
39
+ def self.configuration
40
+ self.include_with_respect_configuration ||= Configuration.new
41
+ end
42
+
43
+ # For global config in an initializer with a block
44
+ def self.configure
45
+ yield(configuration)
46
+ end
47
+
48
+ #### CONFIG ####
49
+ class << self
50
+ attr_accessor :include_with_respect_configuration
51
+ end
52
+
53
+ private
54
+
55
+ def have_respect(action, receiver, module1, *smth)
56
+ message = "#{module1}#{smth.any? ? " with #{smth}" : ''} already #{action} in #{receiver}"
57
+ puts "message: #{message}" if configuration.level == [:error]
58
+ configuration.level.each do |level|
59
+ case level
60
+ when :error
61
+ raise ::IncludeWithRespect::Error, message
62
+ when :warning
63
+ puts message
64
+ when :skip
65
+ @skip_include = true
66
+ else # :silent
67
+ # NOOP
68
+ end
69
+ end
70
+ end
71
+ module_function :have_respect
72
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is an ActiveSupport::Concern that will make other concerns "include with respect"
4
+ # Usage:
5
+ # module MyConcern
6
+ # extend ActiveSupport::Concern
7
+ #
8
+ # included do
9
+ # include IncludeWithRespect::ConcernWithRespect
10
+ # include SomeOtherConcern
11
+ # end
12
+ # end
13
+ module IncludeWithRespect
14
+ module ConcernWithRespect
15
+ extend ActiveSupport::Concern
16
+
17
+ included do
18
+ # Rename standard include to include_without_respect
19
+ define_singleton_method(:include_without_respect, base.method(:include))
20
+ # Rename standard extend to extend_without_respect
21
+ define_singleton_method(:extend_without_respect, base.method(:extend))
22
+ end
23
+
24
+ class_methods do
25
+ # Then define a new version of include,
26
+ # which ultimately calls the original include as include_without_respect
27
+ def include(module1, *smth)
28
+ IncludeWithRespect.include_with_respect(self, module1, *smth)
29
+ end
30
+
31
+ # Then define a new version of extend,
32
+ # which ultimately calls the original extend as extend_without_respect
33
+ def extend(module1, *smth)
34
+ IncludeWithRespect.extend_with_respect(self, module1, *smth)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IncludeWithRespect
4
+ class Configuration
5
+ VALID_LEVELS = %i[warning error skip silent]
6
+ attr_reader :level
7
+
8
+ def initialize(**options)
9
+ self.level = options[:level] || :warning
10
+ validate
11
+ end
12
+
13
+ def level=(value)
14
+ @level = Array(value)
15
+ end
16
+
17
+ def validate
18
+ unexpected = (level - VALID_LEVELS)
19
+ return unless unexpected.any?
20
+
21
+ raise ::IncludeWithRespect::Error, "Unexpected configuration value(s) for level: #{unexpected}"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ class Base
3
+ include IncludeWithRespect::ModuleWithRespect
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module ActiveSupport
2
+ module Concern
3
+ def self.included(base)
4
+ base.send(:include, IncludeWithRespect::ModuleWithRespect)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Usage in a class:
4
+ #
5
+ # class MyClass
6
+ # using IncludeWithRespect::ModuleWithRespect
7
+ # include SomeOtherConcern
8
+ # end
9
+ #
10
+ # Usage in a Module:
11
+ #
12
+ # module MyModule
13
+ # def self.included(base)
14
+ # base.send(:include, IncludeWithRespect::ModuleWithRespect)
15
+ # base.send(:include, SomeOtherModule)
16
+ # end
17
+ # end
18
+ module IncludeWithRespect
19
+ module ModuleWithRespect
20
+ def self.included(base)
21
+ # Rename standard include to include_without_respect
22
+ base.define_singleton_method(:include_without_respect, base.method(:include))
23
+ # Rename standard extend to extend_without_respect
24
+ base.define_singleton_method(:extend_without_respect, base.method(:extend))
25
+ base.extend(ClassMethods)
26
+ end
27
+
28
+ module ClassMethods
29
+ # Define a new version of include,
30
+ # which ultimately calls the original include as include_without_respect
31
+ def include(module1, *smth)
32
+ IncludeWithRespect.include_with_respect(self, module1, *smth)
33
+ end
34
+
35
+ # Define a new version of extend,
36
+ # which ultimately calls the original extend as extend_without_respect
37
+ def extend(module1, *smth)
38
+ IncludeWithRespect.extend_with_respect(self, module1, *smth)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module IncludeWithRespect
2
+ VERSION = '1.0.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,253 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: include_with_respect
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter Boling
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: appraisal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gem-release
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-block_is_expected
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: silent_stream
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: wwtd
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description:
196
+ email:
197
+ - peter.boling@gmail.com
198
+ executables: []
199
+ extensions: []
200
+ extra_rdoc_files: []
201
+ files:
202
+ - ".gitignore"
203
+ - ".rspec"
204
+ - ".ruby-version"
205
+ - ".travis.yml"
206
+ - CODE_OF_CONDUCT.md
207
+ - Gemfile
208
+ - LICENSE
209
+ - README.md
210
+ - Rakefile
211
+ - bin/console
212
+ - bin/setup
213
+ - gemfiles/ruby_2.0.gemfile
214
+ - gemfiles/ruby_2.1.gemfile
215
+ - gemfiles/ruby_2.2.gemfile
216
+ - gemfiles/ruby_2.3.gemfile
217
+ - gemfiles/ruby_2.4.gemfile
218
+ - gemfiles/ruby_2.5.gemfile
219
+ - gemfiles/ruby_2.6.gemfile
220
+ - include_with_respect.gemspec
221
+ - lib/include_with_respect.rb
222
+ - lib/include_with_respect/concern_with_respect.rb
223
+ - lib/include_with_respect/configuration.rb
224
+ - lib/include_with_respect/ext/active_record/base.rb
225
+ - lib/include_with_respect/ext/active_support/concern.rb
226
+ - lib/include_with_respect/module_with_respect.rb
227
+ - lib/include_with_respect/version.rb
228
+ homepage: http://github.com/pboling/include_with_respect
229
+ licenses: []
230
+ metadata:
231
+ homepage_uri: http://github.com/pboling/include_with_respect
232
+ source_code_uri: http://github.com/pboling/include_with_respect
233
+ changelog_uri: http://github.com/pboling/include_with_respect/blob/master/CHANGELOG
234
+ post_install_message:
235
+ rdoc_options: []
236
+ require_paths:
237
+ - lib
238
+ required_ruby_version: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ required_rubygems_version: !ruby/object:Gem::Requirement
244
+ requirements:
245
+ - - ">="
246
+ - !ruby/object:Gem::Version
247
+ version: '0'
248
+ requirements: []
249
+ rubygems_version: 3.0.3
250
+ signing_key:
251
+ specification_version: 4
252
+ summary: Untangle dependency trees
253
+ test_files: []