middlegem 0.1.0 → 0.2.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 +4 -4
- data/.gitignore +4 -0
- data/CHANGELOG.md +6 -1
- data/README.md +17 -0
- data/lib/middlegem/array_definition.rb +18 -2
- data/lib/middlegem/version.rb +1 -1
- data/middlegem.gemspec +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: 33925e2b8f3d95cb564a53b44788717d3068603dbc2a5107f0937819d6967e87
|
4
|
+
data.tar.gz: f3597bc2dfce25d28280dbeed6c61625af875879852b1a67301d2e18e2dd5603
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8107aa2092092b484c3e46a79bb870559e5519a9b2eeaccf34ff6403c3899133926942683dba7564f7e18b6310469fdef2e26ebad46f73a5d81a626359044c6
|
7
|
+
data.tar.gz: 68ed4faa9ee68d24080941b6302816100df2130482ec5d166dcd83f299c75f49bdbee52fcfda5451aac37f8d50b85c8fadc83beab09f83e9bbe5511d8dc112e9
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,9 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.2.0] - 2021-07-18
|
10
|
+
### Added
|
11
|
+
- The ability to change how `ArrayDefinition` matches middleware classes.
|
12
|
+
|
9
13
|
## [0.1.0] - 2021-07-08
|
10
14
|
### Added
|
11
15
|
- The initial `middlegem` gem.
|
12
16
|
|
13
|
-
[Unreleased]: https://github.com/jacoblockard99/middlegem/compare/v0.
|
17
|
+
[Unreleased]: https://github.com/jacoblockard99/middlegem/compare/v0.2.0...HEAD
|
14
18
|
[0.1.0]: https://github.com/jacoblockard99/middlegem/releases/tag/v0.1.0
|
19
|
+
[0.2.0]: https://github.com/jacoblockard99/middlegem/releases/tag/v0.2.0
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Middlegem
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/middlegem)
|
3
4
|
[](https://travis-ci.com/jacoblockard99/middlegem)
|
4
5
|
[](http://inch-ci.org/github/jacoblockard99/middlegem)
|
5
6
|
[](https://codeclimate.com/github/jacoblockard99/middlegem/maintainability)
|
@@ -184,6 +185,22 @@ While this works, the limitations quickly become obvious. Mainly, it requires a
|
|
184
185
|
|
185
186
|
For more complicated scenarios, it is instead recommended that you create your own implementation of `Middlegem::Definition` that allows ordering the middlewares in some other way. Perhaps you could set "priorities" on the middlewares, or organize them into "groups"—the possibilities with this method are limitless!
|
186
187
|
|
188
|
+
### Class Evaluation
|
189
|
+
|
190
|
+
There may be times when you wish to have more control over how exactly `ArrayDefinition` determines the class of a middleware. The default implementation uses `instance_of?`. Perhaps you want to use `is_a?`, or maybe you have an entirely different method for getting the "class" of the middleware. In any case, this can be easily done by overriding `ArrayDefinition#matches_class?`. For example:
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
class CustomArrayDefinition < Middlegem::ArrayDefinition do
|
194
|
+
protected
|
195
|
+
|
196
|
+
def matches_class?(middleware, klass)
|
197
|
+
middleware.is_a? klass
|
198
|
+
end
|
199
|
+
end
|
200
|
+
```
|
201
|
+
|
202
|
+
This would cause all subclasses of a base class to be defined when the base class is.
|
203
|
+
|
187
204
|
## Development
|
188
205
|
|
189
206
|
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.
|
@@ -108,17 +108,33 @@ module Middlegem
|
|
108
108
|
# @param middleware [Object] the middleware to check.
|
109
109
|
# @return [bool] whether the middleware is defined.
|
110
110
|
def defined?(middleware)
|
111
|
-
defined_classes.
|
111
|
+
defined_classes.any? { |c| matches_class?(middleware, c) }
|
112
112
|
end
|
113
113
|
|
114
114
|
# Sorts the given array of middlewares according to this {ArrayDefinition}. Middlewares are
|
115
115
|
# sorted according to the order in which their classes are specified in {#defined_classes}.
|
116
116
|
# If multiple middlewares of the same type are encountered, they will be resolved with the
|
117
117
|
# {#resolver}.
|
118
|
+
# @param middlewares [Array<Object>] the middlewares to sort.
|
119
|
+
# @return [Array<Object>] the sorted middlewares.
|
118
120
|
def sort(middlewares)
|
119
121
|
defined_classes.map { |c| resolver.call(matches(middlewares, c)) }.flatten
|
120
122
|
end
|
121
123
|
|
124
|
+
protected
|
125
|
+
|
126
|
+
# Should determine whether the given middleware's evaluated class is equal to the given one.
|
127
|
+
# The default implementation naturally just uses +instance_of?+, but you are free to
|
128
|
+
# override this method for other situations. You may want is use +is_a?+ instead, for
|
129
|
+
# example, or perhaps a middleware's "class" is based on some other criterion.
|
130
|
+
# @param middleware [Object] the middleware to check.
|
131
|
+
# @param klass [Class] the class against which to check the middleware.
|
132
|
+
# @return [Boolean] whether the given middleware has the given class.
|
133
|
+
# @since 0.2.0
|
134
|
+
def matches_class?(middleware, klass)
|
135
|
+
middleware.instance_of? klass
|
136
|
+
end
|
137
|
+
|
122
138
|
private
|
123
139
|
|
124
140
|
# Gets all the middlewares in the given array whose class is the given class.
|
@@ -126,7 +142,7 @@ module Middlegem
|
|
126
142
|
# @param klass [Class] the class to search for.
|
127
143
|
# @return [Array<Object>] the matched middlewares.
|
128
144
|
def matches(middlewares, klass)
|
129
|
-
middlewares.select { |m|
|
145
|
+
middlewares.select { |m| matches_class?(m, klass) }
|
130
146
|
end
|
131
147
|
end
|
132
148
|
end
|
data/lib/middlegem/version.rb
CHANGED
data/middlegem.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.metadata['homepage_uri'] = spec.homepage
|
21
21
|
spec.metadata['source_code_uri'] = 'https://github.com/jacoblockard99/middlegem'
|
22
|
-
spec.metadata['changelog_uri'] = 'https://github.com/jacoblockard99/middlegem/CHANGELOG.md'
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/jacoblockard99/middlegem/blob/master/CHANGELOG.md'
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
25
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middlegem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -104,7 +104,7 @@ licenses:
|
|
104
104
|
metadata:
|
105
105
|
homepage_uri: https://github.com/jacoblockard99/middlegem
|
106
106
|
source_code_uri: https://github.com/jacoblockard99/middlegem
|
107
|
-
changelog_uri: https://github.com/jacoblockard99/middlegem/CHANGELOG.md
|
107
|
+
changelog_uri: https://github.com/jacoblockard99/middlegem/blob/master/CHANGELOG.md
|
108
108
|
post_install_message:
|
109
109
|
rdoc_options: []
|
110
110
|
require_paths:
|