include_with_respect 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -5
- data/include_with_respect.gemspec +1 -0
- data/lib/include_with_respect.rb +4 -0
- data/lib/include_with_respect/module_with_respect.rb +1 -1
- data/lib/include_with_respect/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b665b596a5848520d367962989de8e898a231879b6bfb5712d8c3cb0f8f2d57
|
4
|
+
data.tar.gz: 71aa1e8906a7e7e4b451c82ecd40ae7bacc676c10ee25ba5dae3e0b311f6243b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a90f2b2e2caa05292e5886df39eea976849ca455b0e2bbcaaf2c1f93ac7d87a87d31ad5e45561a6d78bc0060f08b7c734a4e09a5acdd485dde0c326d6cb6b8b4
|
7
|
+
data.tar.gz: 3ca1816c147a117ea746db2154800d2388d2c1c7c48dcc351efa60225845fe120cc87abc36108ce31aea0be22c0ec3af3a8ffd286b7aee3fcb138bc903d07a79
|
data/README.md
CHANGED
@@ -10,14 +10,13 @@ Modules have hooks on `include` and `extend`, among others. These will run every
|
|
10
10
|
|------------------------ | ----------------------- |
|
11
11
|
| gem name | [include_with_respect][rubygems] |
|
12
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)]
|
13
|
+
| download rank | [![Downloads Today](https://img.shields.io/gem/rd/include_with_respect.svg)][github] |
|
14
14
|
| version | [![Version](https://img.shields.io/gem/v/include_with_respect.svg)][rubygems] |
|
15
15
|
| dependencies | [![Depfu](https://badges.depfu.com/badges/7ab03542cae3755d64038f7b3e7af53e/count.svg)](https://depfu.com/github/pboling/include_with_respect?project_id=10361) |
|
16
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
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
18
|
| maintainability | [![Maintainability](https://api.codeclimate.com/v1/badges/604a8f3a996c008cb2ae/maintainability)](https://codeclimate.com/github/pboling/include_with_respect/maintainability) |
|
19
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
20
|
| homepage | [on Github.com][homepage], [on Railsbling.com][blogpage] |
|
22
21
|
| documentation | [on RDoc.info][documentation] |
|
23
22
|
| Spread ~♡ⓛⓞⓥⓔ♡~ | [🌍 🌎 🌏][about-me], [🍚][crowdrise], [👼][angel-list], [🐛][topcoder], [:shipit:][coderwall], [![Tweet Peter][twitter-followers]][twitter] |
|
@@ -41,7 +40,45 @@ Or install it yourself as:
|
|
41
40
|
|
42
41
|
## Usage
|
43
42
|
|
44
|
-
|
43
|
+
|
44
|
+
### With Ruby `Class`:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
module SomeOtherModule
|
48
|
+
def self.included(base)
|
49
|
+
base.send(:include, SomeModule)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class MyClass
|
54
|
+
include IncludeWithRespect::ModuleWithRespect
|
55
|
+
include SomeModule
|
56
|
+
include SomeOtherModule
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
Because `SomeOtherModule` also includes `SomeModule` two things will happen that normally do not:
|
61
|
+
1. a warning will be printed (via `puts`)
|
62
|
+
2. the duplicate inclusion will be skipped (meaning the hooks will not run again)
|
63
|
+
- 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!
|
64
|
+
|
65
|
+
### With Ruby `Module`:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
module MyModule
|
69
|
+
def self.included(base)
|
70
|
+
base.send(:include, IncludeWithRespect::ModuleWithRespect)
|
71
|
+
base.send(:include, SomeModule)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
Then if `MyModule` is included somewhere that also includes `SomeModule` two things will happen that normally do not:
|
77
|
+
1. a warning will be printed (via `puts`)
|
78
|
+
2. the duplicate inclusion will be skipped (meaning the hooks will not run again)
|
79
|
+
- 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!
|
80
|
+
|
81
|
+
### With Rails' `ActiveSupport::Concern`
|
45
82
|
|
46
83
|
```ruby
|
47
84
|
module MyConcern
|
@@ -58,6 +95,24 @@ Then if `MyConcern` is included somewhere that also includes `SomeOtherConcern`
|
|
58
95
|
2. the duplicate inclusion will be skipped (meaning the hooks will not run again)
|
59
96
|
- 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
97
|
|
98
|
+
### Raw Usage (more intrusive code changes)
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
module SomeOtherModule
|
102
|
+
def self.included(base)
|
103
|
+
base.send(:include, SomeModule)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class MyClass
|
108
|
+
include IncludeWithRespect
|
109
|
+
include_with_respect SomeModule
|
110
|
+
include_with_respect SomeOtherModule
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
Same results as the other usage examples.
|
115
|
+
|
61
116
|
## Development
|
62
117
|
|
63
118
|
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.
|
@@ -95,7 +150,7 @@ For example:
|
|
95
150
|
|
96
151
|
## Legal
|
97
152
|
|
98
|
-
* [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)]
|
153
|
+
* [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][mit]
|
99
154
|
* Copyright (c) 2019 [Peter H. Boling][peterboling] of [Rails Bling][railsbling]
|
100
155
|
|
101
156
|
[semver]: http://semver.org/
|
@@ -113,4 +168,6 @@ For example:
|
|
113
168
|
[topcoder]: https://www.topcoder.com/members/pboling/
|
114
169
|
[coderwall]: http://coderwall.com/pboling
|
115
170
|
[twitter-followers]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow
|
116
|
-
[twitter]: http://twitter.com/galtzo
|
171
|
+
[twitter]: http://twitter.com/galtzo
|
172
|
+
[blogpage]: http://www.railsbling.com/include_with_respect
|
173
|
+
[github]: https://github.com/pboling/include_with_respect
|
@@ -9,6 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ['peter.boling@gmail.com']
|
10
10
|
|
11
11
|
spec.summary = 'Untangle dependency trees'
|
12
|
+
spec.description = 'Find out if your Module include/extend hooks are misbehaving!'
|
12
13
|
spec.homepage = 'http://github.com/pboling/include_with_respect'
|
13
14
|
|
14
15
|
spec.metadata['homepage_uri'] = spec.homepage
|
data/lib/include_with_respect.rb
CHANGED
@@ -10,11 +10,15 @@ require 'include_with_respect/module_with_respect'
|
|
10
10
|
require 'include_with_respect/concern_with_respect' if defined?(ActiveSupport)
|
11
11
|
|
12
12
|
# [Sometimes] We should respect our ancestors.
|
13
|
+
#
|
14
|
+
# ## Raw Usage (see lib/include_with_respect/module_with_respect for the non-intrusive interface)
|
15
|
+
#
|
13
16
|
# If you swap `include` for `include_with_respect`, when a module is already among our ancestors does not re-include it.
|
14
17
|
# Why?
|
15
18
|
# Some modules have side effects on the `included` hook which can be problematic if they run more than once.
|
16
19
|
# Additionally, including a module multiple times will override the original include,
|
17
20
|
# but in a messy way, with potentially dangerous side effects and shared state.
|
21
|
+
#
|
18
22
|
module IncludeWithRespect
|
19
23
|
class Error < StandardError; end
|
20
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: include_with_respect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -192,7 +192,7 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
-
description:
|
195
|
+
description: Find out if your Module include/extend hooks are misbehaving!
|
196
196
|
email:
|
197
197
|
- peter.boling@gmail.com
|
198
198
|
executables: []
|