before_hooks 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/.gitignore +18 -18
- data/.rspec +3 -3
- data/.travis.yml +11 -11
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +202 -189
- data/Rakefile +6 -6
- data/before_hooks.gemspec +30 -30
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/before_hooks.rb +54 -54
- data/lib/before_hooks/version.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0462326f4fff644a5ddb26fe00995cd60aab53381adbbce40d7ea0295b793c9
|
|
4
|
+
data.tar.gz: b2424bca9a7a32853ef24e6502fd98e4fff1976355a9eccc2bf12c14715796f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b1a85725f06406cae9c0299c8915f4df3aa8552f3cea7e3e1bd79e4705c30220bc5baa35810a4af351ad26dc82f882b996fed773d66de2c8d3269a18a5709151
|
|
7
|
+
data.tar.gz: f36f50b54d79633deb07b24253fd2cf47da6b0f06b3d35251d93614fc8f93f547ac39b03d8ab46547ccedae450d347782dfd4e2e5071db8fb6a2660f7fd50f34
|
data/.gitignore
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/.bundle/
|
|
2
|
-
/.yardoc
|
|
3
|
-
/_yardoc/
|
|
4
|
-
/coverage/
|
|
5
|
-
/doc/
|
|
6
|
-
/pkg/
|
|
7
|
-
/spec/reports/
|
|
8
|
-
/tmp/
|
|
9
|
-
|
|
10
|
-
# rspec failure tracking
|
|
11
|
-
.rspec_status
|
|
12
|
-
|
|
13
|
-
.byebug_history
|
|
14
|
-
|
|
15
|
-
*.gem
|
|
16
|
-
|
|
17
|
-
Gemfile.lock
|
|
18
|
-
gemfiles/*.lock
|
|
1
|
+
/.bundle/
|
|
2
|
+
/.yardoc
|
|
3
|
+
/_yardoc/
|
|
4
|
+
/coverage/
|
|
5
|
+
/doc/
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/tmp/
|
|
9
|
+
|
|
10
|
+
# rspec failure tracking
|
|
11
|
+
.rspec_status
|
|
12
|
+
|
|
13
|
+
.byebug_history
|
|
14
|
+
|
|
15
|
+
*.gem
|
|
16
|
+
|
|
17
|
+
Gemfile.lock
|
|
18
|
+
gemfiles/*.lock
|
data/.rspec
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
--format documentation
|
|
2
|
-
--color
|
|
3
|
-
--require spec_helper
|
|
1
|
+
--format documentation
|
|
2
|
+
--color
|
|
3
|
+
--require spec_helper
|
data/.travis.yml
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
---
|
|
2
|
-
sudo: false
|
|
3
|
-
language: ruby
|
|
4
|
-
cache: bundler
|
|
5
|
-
rvm:
|
|
6
|
-
- 2.0.0
|
|
7
|
-
- 2.2.7
|
|
8
|
-
- 2.3.4
|
|
9
|
-
- 2.4.1
|
|
10
|
-
- 2.5.1
|
|
11
|
-
before_install: gem install bundler -v 1.16.4
|
|
1
|
+
---
|
|
2
|
+
sudo: false
|
|
3
|
+
language: ruby
|
|
4
|
+
cache: bundler
|
|
5
|
+
rvm:
|
|
6
|
+
- 2.0.0
|
|
7
|
+
- 2.2.7
|
|
8
|
+
- 2.3.4
|
|
9
|
+
- 2.4.1
|
|
10
|
+
- 2.5.1
|
|
11
|
+
before_install: gem install bundler -v 1.16.4
|
data/CODE_OF_CONDUCT.md
CHANGED
|
@@ -1,74 +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 jrpolidario@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/
|
|
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 jrpolidario@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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
source "https://rubygems.org"
|
|
2
|
-
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
4
|
-
|
|
5
|
-
# Specify your gem's dependencies in before_hooks.gemspec
|
|
6
|
-
gemspec
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
4
|
+
|
|
5
|
+
# Specify your gem's dependencies in before_hooks.gemspec
|
|
6
|
+
gemspec
|
data/LICENSE.txt
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 Jules Roman B. Polidario
|
|
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.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Jules Roman B. Polidario
|
|
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
CHANGED
|
@@ -1,189 +1,202 @@
|
|
|
1
|
-
# BeforeHooks
|
|
2
|
-
|
|
3
|
-
[](https://travis-ci.org/jrpolidario/before_hooks)
|
|
4
|
-
|
|
5
|
-
Adds `before_extended`, `before_included`, and `before_prepended` methods hooks which would be called before the standard `extended`, `included`, and `prepended` Ruby hooks, respectively.
|
|
6
|
-
|
|
7
|
-
Especially useful when you require to "do" something just before the module gets `extended`, `included`, or `prepended` to a module/class. In particular, in my specific case, I needed to "do" something first if a specific method already exists in the base class before being extended, of which then I'd use `before_extended`.
|
|
8
|
-
|
|
9
|
-
## Dependencies
|
|
10
|
-
|
|
11
|
-
* **Ruby ~> 2.0**
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
Add this line to your application's Gemfile:
|
|
16
|
-
|
|
17
|
-
```ruby
|
|
18
|
-
gem 'before_hooks', '~> 0.1'
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
And then execute:
|
|
22
|
-
|
|
23
|
-
$ bundle
|
|
24
|
-
|
|
25
|
-
Or install it yourself as:
|
|
26
|
-
|
|
27
|
-
$ gem install before_hooks
|
|
28
|
-
|
|
29
|
-
## Usage
|
|
30
|
-
|
|
31
|
-
### `before_included` Example
|
|
32
|
-
|
|
33
|
-
```ruby
|
|
34
|
-
require 'bundler/setup'
|
|
35
|
-
require 'before_hooks'
|
|
36
|
-
|
|
37
|
-
module SomeModule
|
|
38
|
-
# not required to be defined
|
|
39
|
-
def self.before_included(base)
|
|
40
|
-
pp 'SomeModule#before_included'
|
|
41
|
-
pp base
|
|
42
|
-
pp base.ancestors
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# not required to be defined:
|
|
46
|
-
def self.included(base)
|
|
47
|
-
pp 'SomeModule#included'
|
|
48
|
-
pp base
|
|
49
|
-
pp base.ancestors
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
class SomeClass
|
|
54
|
-
include SomeModule
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# upon code execution, will print...
|
|
58
|
-
|
|
59
|
-
=begin
|
|
60
|
-
|
|
61
|
-
"SomeModule#before_included"
|
|
62
|
-
SomeClass
|
|
63
|
-
[SomeClass, Object, PP::ObjectMixin, Kernel, BasicObject]
|
|
64
|
-
"SomeModule#included"
|
|
65
|
-
SomeClass
|
|
66
|
-
[SomeClass, SomeModule, Object, PP::ObjectMixin, Kernel, BasicObject]
|
|
67
|
-
|
|
68
|
-
=end
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### `before_extended` Example
|
|
72
|
-
|
|
73
|
-
```ruby
|
|
74
|
-
require 'bundler/setup'
|
|
75
|
-
require 'before_hooks'
|
|
76
|
-
|
|
77
|
-
module SomeModule
|
|
78
|
-
# not required to be defined
|
|
79
|
-
def self.before_extended(base)
|
|
80
|
-
pp 'SomeModule#before_extended'
|
|
81
|
-
pp base
|
|
82
|
-
pp base.singleton_class.ancestors
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# not required to be defined:
|
|
86
|
-
def self.extended(base)
|
|
87
|
-
pp 'SomeModule#extended'
|
|
88
|
-
pp base
|
|
89
|
-
pp base.singleton_class.ancestors
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
class SomeClass
|
|
94
|
-
extend SomeModule
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# upon code execution, will print...
|
|
98
|
-
|
|
99
|
-
=begin
|
|
100
|
-
|
|
101
|
-
"SomeModule#before_extended"
|
|
102
|
-
SomeClass
|
|
103
|
-
[#<Class:SomeClass>,
|
|
104
|
-
#<Class:Object>,
|
|
105
|
-
#<Class:BasicObject>,
|
|
106
|
-
Class,
|
|
107
|
-
BeforeHooks,
|
|
108
|
-
Module,
|
|
109
|
-
Object,
|
|
110
|
-
PP::ObjectMixin,
|
|
111
|
-
Kernel,
|
|
112
|
-
BasicObject]
|
|
113
|
-
"SomeModule#extended"
|
|
114
|
-
SomeClass
|
|
115
|
-
[#<Class:SomeClass>,
|
|
116
|
-
SomeModule,
|
|
117
|
-
#<Class:Object>,
|
|
118
|
-
#<Class:BasicObject>,
|
|
119
|
-
Class,
|
|
120
|
-
BeforeHooks,
|
|
121
|
-
Module,
|
|
122
|
-
Object,
|
|
123
|
-
PP::ObjectMixin,
|
|
124
|
-
Kernel,
|
|
125
|
-
BasicObject]
|
|
126
|
-
|
|
127
|
-
=end
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### `before_prepended` Example
|
|
131
|
-
|
|
132
|
-
```ruby
|
|
133
|
-
require 'bundler/setup'
|
|
134
|
-
require 'before_hooks'
|
|
135
|
-
|
|
136
|
-
module SomeModule
|
|
137
|
-
# not required to be defined
|
|
138
|
-
def self.before_prepended(base)
|
|
139
|
-
pp 'SomeModule#before_prepended'
|
|
140
|
-
pp base
|
|
141
|
-
pp base.ancestors
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
# not required to be defined:
|
|
145
|
-
def self.prepended(base)
|
|
146
|
-
pp 'SomeModule#prepended'
|
|
147
|
-
pp base
|
|
148
|
-
pp base.ancestors
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
class SomeClass
|
|
153
|
-
prepend SomeModule
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
# upon code execution, will print...
|
|
157
|
-
|
|
158
|
-
=begin
|
|
159
|
-
|
|
160
|
-
"SomeModule#before_prepended"
|
|
161
|
-
SomeClass
|
|
162
|
-
[SomeClass, Object, PP::ObjectMixin, Kernel, BasicObject]
|
|
163
|
-
"SomeModule#prepended"
|
|
164
|
-
SomeClass
|
|
165
|
-
[SomeModule, SomeClass, Object, PP::ObjectMixin, Kernel, BasicObject]
|
|
166
|
-
|
|
167
|
-
=end
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
## TODOs
|
|
171
|
-
* Need help or further research on how to support and implement `before_inherited`, `before_method_added`, and `before_method_removed`, because "prepend" trick doesn't readily work with them.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
1
|
+
# BeforeHooks
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/jrpolidario/before_hooks)
|
|
4
|
+
|
|
5
|
+
Adds `before_extended`, `before_included`, and `before_prepended` methods hooks which would be called before the standard `extended`, `included`, and `prepended` Ruby hooks, respectively.
|
|
6
|
+
|
|
7
|
+
Especially useful when you require to "do" something just before the module gets `extended`, `included`, or `prepended` to a module/class. In particular, in my specific case, I needed to "do" something first if a specific method already exists in the base class before being extended, of which then I'd use `before_extended`.
|
|
8
|
+
|
|
9
|
+
## Dependencies
|
|
10
|
+
|
|
11
|
+
* **Ruby ~> 2.0**
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add this line to your application's Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'before_hooks', '~> 0.1'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
And then execute:
|
|
22
|
+
|
|
23
|
+
$ bundle
|
|
24
|
+
|
|
25
|
+
Or install it yourself as:
|
|
26
|
+
|
|
27
|
+
$ gem install before_hooks
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### `before_included` Example
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
require 'bundler/setup'
|
|
35
|
+
require 'before_hooks'
|
|
36
|
+
|
|
37
|
+
module SomeModule
|
|
38
|
+
# not required to be defined
|
|
39
|
+
def self.before_included(base)
|
|
40
|
+
pp 'SomeModule#before_included'
|
|
41
|
+
pp base
|
|
42
|
+
pp base.ancestors
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# not required to be defined:
|
|
46
|
+
def self.included(base)
|
|
47
|
+
pp 'SomeModule#included'
|
|
48
|
+
pp base
|
|
49
|
+
pp base.ancestors
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class SomeClass
|
|
54
|
+
include SomeModule
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# upon code execution, will print...
|
|
58
|
+
|
|
59
|
+
=begin
|
|
60
|
+
|
|
61
|
+
"SomeModule#before_included"
|
|
62
|
+
SomeClass
|
|
63
|
+
[SomeClass, Object, PP::ObjectMixin, Kernel, BasicObject]
|
|
64
|
+
"SomeModule#included"
|
|
65
|
+
SomeClass
|
|
66
|
+
[SomeClass, SomeModule, Object, PP::ObjectMixin, Kernel, BasicObject]
|
|
67
|
+
|
|
68
|
+
=end
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### `before_extended` Example
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
require 'bundler/setup'
|
|
75
|
+
require 'before_hooks'
|
|
76
|
+
|
|
77
|
+
module SomeModule
|
|
78
|
+
# not required to be defined
|
|
79
|
+
def self.before_extended(base)
|
|
80
|
+
pp 'SomeModule#before_extended'
|
|
81
|
+
pp base
|
|
82
|
+
pp base.singleton_class.ancestors
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# not required to be defined:
|
|
86
|
+
def self.extended(base)
|
|
87
|
+
pp 'SomeModule#extended'
|
|
88
|
+
pp base
|
|
89
|
+
pp base.singleton_class.ancestors
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
class SomeClass
|
|
94
|
+
extend SomeModule
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# upon code execution, will print...
|
|
98
|
+
|
|
99
|
+
=begin
|
|
100
|
+
|
|
101
|
+
"SomeModule#before_extended"
|
|
102
|
+
SomeClass
|
|
103
|
+
[#<Class:SomeClass>,
|
|
104
|
+
#<Class:Object>,
|
|
105
|
+
#<Class:BasicObject>,
|
|
106
|
+
Class,
|
|
107
|
+
BeforeHooks,
|
|
108
|
+
Module,
|
|
109
|
+
Object,
|
|
110
|
+
PP::ObjectMixin,
|
|
111
|
+
Kernel,
|
|
112
|
+
BasicObject]
|
|
113
|
+
"SomeModule#extended"
|
|
114
|
+
SomeClass
|
|
115
|
+
[#<Class:SomeClass>,
|
|
116
|
+
SomeModule,
|
|
117
|
+
#<Class:Object>,
|
|
118
|
+
#<Class:BasicObject>,
|
|
119
|
+
Class,
|
|
120
|
+
BeforeHooks,
|
|
121
|
+
Module,
|
|
122
|
+
Object,
|
|
123
|
+
PP::ObjectMixin,
|
|
124
|
+
Kernel,
|
|
125
|
+
BasicObject]
|
|
126
|
+
|
|
127
|
+
=end
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### `before_prepended` Example
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
require 'bundler/setup'
|
|
134
|
+
require 'before_hooks'
|
|
135
|
+
|
|
136
|
+
module SomeModule
|
|
137
|
+
# not required to be defined
|
|
138
|
+
def self.before_prepended(base)
|
|
139
|
+
pp 'SomeModule#before_prepended'
|
|
140
|
+
pp base
|
|
141
|
+
pp base.ancestors
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# not required to be defined:
|
|
145
|
+
def self.prepended(base)
|
|
146
|
+
pp 'SomeModule#prepended'
|
|
147
|
+
pp base
|
|
148
|
+
pp base.ancestors
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
class SomeClass
|
|
153
|
+
prepend SomeModule
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# upon code execution, will print...
|
|
157
|
+
|
|
158
|
+
=begin
|
|
159
|
+
|
|
160
|
+
"SomeModule#before_prepended"
|
|
161
|
+
SomeClass
|
|
162
|
+
[SomeClass, Object, PP::ObjectMixin, Kernel, BasicObject]
|
|
163
|
+
"SomeModule#prepended"
|
|
164
|
+
SomeClass
|
|
165
|
+
[SomeModule, SomeClass, Object, PP::ObjectMixin, Kernel, BasicObject]
|
|
166
|
+
|
|
167
|
+
=end
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## TODOs
|
|
171
|
+
* Need help or further research on how to support and implement `before_inherited`, `before_method_added`, and `before_method_removed`, because "prepend" trick doesn't readily work with them.
|
|
172
|
+
* Thanks to [@Valaramech](https://www.reddit.com/r/ruby/comments/atwg8g/just_published_a_small_gem_before_hooks/eh3uyhw/) for suggesting to support "block" DSL, and is now a TODO.
|
|
173
|
+
|
|
174
|
+
## Development
|
|
175
|
+
|
|
176
|
+
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.
|
|
177
|
+
|
|
178
|
+
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).
|
|
179
|
+
|
|
180
|
+
## Contributing
|
|
181
|
+
|
|
182
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jrpolidario/before_hooks. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
183
|
+
|
|
184
|
+
## Special Thanks
|
|
185
|
+
|
|
186
|
+
* [@jb3689](https://www.reddit.com/r/ruby/comments/atwg8g/just_published_a_small_gem_before_hooks/ehc7851/) for suggesting to use "dynamic-matching" `.respond_to? :some_method` instead of `.singleton_class.instance_methods.include? :some_method`
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
191
|
+
|
|
192
|
+
## Code of Conduct
|
|
193
|
+
|
|
194
|
+
Everyone interacting in the BeforeHooks project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jrpolidario/before_hooks/blob/master/CODE_OF_CONDUCT.md).
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
## Changelog
|
|
198
|
+
|
|
199
|
+
* 0.1.4
|
|
200
|
+
* Now using "dynamic-matching" `.respond_to? :some_method` instead of `.singleton_class.instance_methods.include? :some_method`; thanks to [@jb3689](https://www.reddit.com/r/ruby/comments/atwg8g/just_published_a_small_gem_before_hooks/ehc7851/)
|
|
201
|
+
* 0.1.3
|
|
202
|
+
* Initial release
|
data/Rakefile
CHANGED
|
@@ -1,6 +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
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require "rspec/core/rake_task"
|
|
3
|
+
|
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
5
|
+
|
|
6
|
+
task :default => :spec
|
data/before_hooks.gemspec
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'before_hooks/version'
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name = 'before_hooks'
|
|
8
|
-
spec.version = BeforeHooks::VERSION
|
|
9
|
-
spec.authors = ['Jules Roman Polidario']
|
|
10
|
-
spec.email = ['jrpolidario@gmail.com']
|
|
11
|
-
|
|
12
|
-
spec.summary = 'Adds `before_extended`, `before_included`, and `before_prepended` methods hooks which would be called before the standard `extended`, `included`, and `prepended` Ruby hooks, respectively.'
|
|
13
|
-
spec.description = 'Adds `before_extended`, `before_included`, and `before_prepended` methods hooks which would be called before the standard `extended`, `included`, and `prepended` Ruby hooks, respectively. Especially useful when you require to "do" something just before the module gets `extended` or `included` to a module/class. In particular, in my specific case, I needed to "do" something if a specific method already exists in the `base` class.'
|
|
14
|
-
spec.homepage = 'https://github.com/jrpolidario/before_hooks'
|
|
15
|
-
spec.license = 'MIT'
|
|
16
|
-
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
-
f.match(%r{^(test|spec|features)/})
|
|
19
|
-
end
|
|
20
|
-
spec.bindir = 'exe'
|
|
21
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
-
spec.require_paths = ['lib']
|
|
23
|
-
|
|
24
|
-
spec.required_ruby_version = '~> 2.0'
|
|
25
|
-
|
|
26
|
-
spec.add_development_dependency 'byebug', '~> 9.0'
|
|
27
|
-
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
28
|
-
spec.add_development_dependency 'rspec', '~> 3.7.0'
|
|
29
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
|
30
|
-
end
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'before_hooks/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'before_hooks'
|
|
8
|
+
spec.version = BeforeHooks::VERSION
|
|
9
|
+
spec.authors = ['Jules Roman Polidario']
|
|
10
|
+
spec.email = ['jrpolidario@gmail.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = 'Adds `before_extended`, `before_included`, and `before_prepended` methods hooks which would be called before the standard `extended`, `included`, and `prepended` Ruby hooks, respectively.'
|
|
13
|
+
spec.description = 'Adds `before_extended`, `before_included`, and `before_prepended` methods hooks which would be called before the standard `extended`, `included`, and `prepended` Ruby hooks, respectively. Especially useful when you require to "do" something just before the module gets `extended` or `included` to a module/class. In particular, in my specific case, I needed to "do" something if a specific method already exists in the `base` class.'
|
|
14
|
+
spec.homepage = 'https://github.com/jrpolidario/before_hooks'
|
|
15
|
+
spec.license = 'MIT'
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = 'exe'
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ['lib']
|
|
23
|
+
|
|
24
|
+
spec.required_ruby_version = '~> 2.0'
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency 'byebug', '~> 9.0'
|
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.7.0'
|
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
30
|
+
end
|
data/bin/console
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "before_hooks"
|
|
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__)
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "before_hooks"
|
|
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
CHANGED
|
@@ -1,8 +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
|
|
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
|
data/lib/before_hooks.rb
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
require 'before_hooks/version'
|
|
2
|
-
|
|
3
|
-
module BeforeHooks
|
|
4
|
-
def extend(*modules)
|
|
5
|
-
modules.each do |_module|
|
|
6
|
-
if _module.
|
|
7
|
-
_module.before_extended(self)
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
super
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def include(*modules)
|
|
15
|
-
modules.each do |_module|
|
|
16
|
-
if _module.
|
|
17
|
-
_module.before_included(self)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
super
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def prepend(*modules)
|
|
25
|
-
modules.each do |_module|
|
|
26
|
-
if _module.
|
|
27
|
-
_module.before_prepended(self)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
super
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# # TODO: add a `before_method_added` and `before_method_reoved`; not yet working; couldn't yet think of a solution
|
|
35
|
-
# def method_added(method_name)
|
|
36
|
-
# puts 'METHOD ADDED!'
|
|
37
|
-
# puts singleton_class.instance_methods.include? :before_method_added
|
|
38
|
-
# if singleton_class.instance_methods.include? :before_method_added
|
|
39
|
-
# before_method_added(args)
|
|
40
|
-
# end
|
|
41
|
-
#
|
|
42
|
-
# super
|
|
43
|
-
# end
|
|
44
|
-
#
|
|
45
|
-
# def method_removed(*args)
|
|
46
|
-
# if singleton_class.instance_methods.include? :before_method_removed
|
|
47
|
-
# before_method_removed(args)
|
|
48
|
-
# end
|
|
49
|
-
#
|
|
50
|
-
# super
|
|
51
|
-
# end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
Module.send(:prepend, BeforeHooks)
|
|
1
|
+
require 'before_hooks/version'
|
|
2
|
+
|
|
3
|
+
module BeforeHooks
|
|
4
|
+
def extend(*modules)
|
|
5
|
+
modules.each do |_module|
|
|
6
|
+
if _module.respond_to? :before_extended
|
|
7
|
+
_module.before_extended(self)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
super
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def include(*modules)
|
|
15
|
+
modules.each do |_module|
|
|
16
|
+
if _module.respond_to? :before_included
|
|
17
|
+
_module.before_included(self)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
super
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def prepend(*modules)
|
|
25
|
+
modules.each do |_module|
|
|
26
|
+
if _module.respond_to? :before_prepended
|
|
27
|
+
_module.before_prepended(self)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
super
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# # TODO: add a `before_method_added` and `before_method_reoved`; not yet working; couldn't yet think of a solution
|
|
35
|
+
# def method_added(method_name)
|
|
36
|
+
# puts 'METHOD ADDED!'
|
|
37
|
+
# puts singleton_class.instance_methods.include? :before_method_added
|
|
38
|
+
# if singleton_class.instance_methods.include? :before_method_added
|
|
39
|
+
# before_method_added(args)
|
|
40
|
+
# end
|
|
41
|
+
#
|
|
42
|
+
# super
|
|
43
|
+
# end
|
|
44
|
+
#
|
|
45
|
+
# def method_removed(*args)
|
|
46
|
+
# if singleton_class.instance_methods.include? :before_method_removed
|
|
47
|
+
# before_method_removed(args)
|
|
48
|
+
# end
|
|
49
|
+
#
|
|
50
|
+
# super
|
|
51
|
+
# end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
Module.send(:prepend, BeforeHooks)
|
data/lib/before_hooks/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module BeforeHooks
|
|
2
|
-
VERSION = '0.1.
|
|
3
|
-
end
|
|
1
|
+
module BeforeHooks
|
|
2
|
+
VERSION = '0.1.4'
|
|
3
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: before_hooks
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jules Roman Polidario
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-03-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: byebug
|