module_methods 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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +102 -0
- data/lib/module_methods.rb +4 -0
- data/lib/module_methods/extension.rb +34 -0
- data/lib/module_methods/version.rb +5 -0
- metadata +209 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8de4135d88143383ce1af8609baf0f60393a1064006c8957fe39364e90532524
|
4
|
+
data.tar.gz: 957077182635bfbc3f6fca75a5c503247db42bfe23b1f5105db2445d080d9309
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5fd1a14c5a02d4522cf73dd811d889be4af86554a1830dd10ac64fd1e88cf20d4ff2496738490152ac7e72f3f5e1d58a76e95663de74b665ec2245f9e94e08f9
|
7
|
+
data.tar.gz: aee4afbe5f4558954f9f99b7adf944a2f4e490f2ec02a0f8a85e856c849c917be7a7f5fc157624ebfccbc69e3fdce7175e1653405734ded34edd61a4fdfb536d
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Alexander Popov
|
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
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Module Methods
|
2
|
+
|
3
|
+

|
4
|
+
[](https://codecov.io/gh/AlexWayfer/module_methods)
|
5
|
+
[](https://codeclimate.com/github/AlexWayfer/module_methods)
|
6
|
+

|
7
|
+
[](https://inch-ci.org/github/AlexWayfer/module_methods)
|
8
|
+
[](https://github.com/AlexWayfer/module_methods/blob/master/LICENSE)
|
9
|
+
[](https://rubygems.org/gems/module_methods)
|
10
|
+
|
11
|
+
Extendable module for modules with instance and class methods.
|
12
|
+
These modules can be included into each other modules and saving all chain,
|
13
|
+
including `inherited` or `included` (class) methods.
|
14
|
+
|
15
|
+
There are no conflicts with `ActiveSupport::Concern`.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'module_methods'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
```shell
|
28
|
+
bundle install
|
29
|
+
```
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
```shell
|
34
|
+
gem install module_methods
|
35
|
+
```
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'module_methods'
|
41
|
+
|
42
|
+
module SomeCommonCode
|
43
|
+
extend ::ModuleMethods::Extension
|
44
|
+
|
45
|
+
module ClassMethods
|
46
|
+
def inherited(klass)
|
47
|
+
## manipulations with klass
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def some_method
|
52
|
+
## this is instance method
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module MoreSpecificCommonCode
|
57
|
+
include SomeCommonCode
|
58
|
+
|
59
|
+
module ClassMethods
|
60
|
+
def inherited(klass)
|
61
|
+
## you can control the order of `inherited` execution by `super`
|
62
|
+
## this `super` executes `inherited` in `SomeCommonCode`
|
63
|
+
super
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def some_another_method
|
68
|
+
## This is another instance method.
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class BaseClass
|
73
|
+
include MoreSpecificCommonCode
|
74
|
+
|
75
|
+
## Instance methods from modules are here.
|
76
|
+
end
|
77
|
+
|
78
|
+
class EndPoint < BaseClass
|
79
|
+
## Both `inherited` from `SomeCommonCode` and `MoreSpecificCommonCode`
|
80
|
+
## are executing here; private methods from modules are also here.
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
After checking out the repo, run `bundle install` to install dependencies.
|
87
|
+
Then, run `bundle exec rake spec` to run the tests.
|
88
|
+
|
89
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
90
|
+
To release a new version, update the version number in `version.rb`,
|
91
|
+
and then run `bundle exec rake release`, which will create a git tag
|
92
|
+
for the version, push git commits and tags, and push the `.gem` file
|
93
|
+
to [rubygems.org](https://rubygems.org).
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/module_methods).
|
98
|
+
|
99
|
+
## License
|
100
|
+
|
101
|
+
The gem is available as open source under the terms of the
|
102
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ModuleMethods
|
4
|
+
## Module for module methods, because this module can be included
|
5
|
+
## into other modules before including into classes.
|
6
|
+
module Extension
|
7
|
+
## Getter for saving the whole chain of including and extending (nested `ClassMethods`)
|
8
|
+
def modules_with_class_methods
|
9
|
+
@modules_with_class_methods ||= [self]
|
10
|
+
end
|
11
|
+
|
12
|
+
## Main logic, which will be applied after extending with this module
|
13
|
+
## @param base [Module, Class, nil] a module or a class in which extended module
|
14
|
+
## will be included
|
15
|
+
## @yield a block just will be passed to the `super`;
|
16
|
+
## it's for `ActiveSupport::Concern` compatibility
|
17
|
+
def included(base = nil, &block)
|
18
|
+
super
|
19
|
+
|
20
|
+
return unless base
|
21
|
+
|
22
|
+
if base.instance_of? Module
|
23
|
+
base.extend ::ModuleMethods::Extension
|
24
|
+
base.modules_with_class_methods.unshift(*modules_with_class_methods)
|
25
|
+
end
|
26
|
+
|
27
|
+
modules_with_class_methods.each do |module_with_class_methods|
|
28
|
+
next unless module_with_class_methods.const_defined?(:ClassMethods, false)
|
29
|
+
|
30
|
+
base.extend module_with_class_methods::ClassMethods
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: module_methods
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Popov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.18.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.18.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.86.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.86.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-performance
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: gem_toys
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.1.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.1.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: toys
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.10.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.10.0
|
167
|
+
description: |
|
168
|
+
Extendable module for modules with instance and class methods.
|
169
|
+
These modules can be included into each other modules and saving all chain,
|
170
|
+
including `inherited` or `included` (class) methods.
|
171
|
+
email:
|
172
|
+
- alex.wayfer@gmail.com
|
173
|
+
executables: []
|
174
|
+
extensions: []
|
175
|
+
extra_rdoc_files: []
|
176
|
+
files:
|
177
|
+
- CHANGELOG.md
|
178
|
+
- LICENSE.txt
|
179
|
+
- README.md
|
180
|
+
- lib/module_methods.rb
|
181
|
+
- lib/module_methods/extension.rb
|
182
|
+
- lib/module_methods/version.rb
|
183
|
+
homepage: https://github.com/AlexWayfer/module_methods
|
184
|
+
licenses:
|
185
|
+
- MIT
|
186
|
+
metadata:
|
187
|
+
source_code_uri: https://github.com/AlexWayfer/module_methods
|
188
|
+
homepage_uri: https://github.com/AlexWayfer/module_methods
|
189
|
+
changelog_uri: https://github.com/AlexWayfer/module_methods/blob/master/CHANGELOG.md
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options: []
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '2.5'
|
199
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
requirements: []
|
205
|
+
rubygems_version: 3.1.2
|
206
|
+
signing_key:
|
207
|
+
specification_version: 4
|
208
|
+
summary: Extendable module for modules with instance and class methods.
|
209
|
+
test_files: []
|