middlegem 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8e1dd451fcba2d15305534945c4d6fe88c7f6c9fb29c8e8059241503291432b
4
- data.tar.gz: 61fcd25df93bb9902e6a85815ab6b63696c6c2f6d753cceeac4afa521143ca12
3
+ metadata.gz: 33925e2b8f3d95cb564a53b44788717d3068603dbc2a5107f0937819d6967e87
4
+ data.tar.gz: f3597bc2dfce25d28280dbeed6c61625af875879852b1a67301d2e18e2dd5603
5
5
  SHA512:
6
- metadata.gz: 95319c1cc7be36e04290c0a30e3494834dea8b9aef142ca1c44582a80ba9037a9325efb7a764dff32c1483e591c62ca14794d07c4c810d29dcf171c6e40eb171
7
- data.tar.gz: 5790037f20f4c2a7b88f894c74377bd1ca75031ebc87c4c3fc601e3d4b9de21436f11a5aeb7f28b908da0462ef8962d9cfadbfbfdf491781faee122141a74ec8
6
+ metadata.gz: d8107aa2092092b484c3e46a79bb870559e5519a9b2eeaccf34ff6403c3899133926942683dba7564f7e18b6310469fdef2e26ebad46f73a5d81a626359044c6
7
+ data.tar.gz: 68ed4faa9ee68d24080941b6302816100df2130482ec5d166dcd83f299c75f49bdbee52fcfda5451aac37f8d50b85c8fadc83beab09f83e9bbe5511d8dc112e9
data/.gitignore CHANGED
@@ -19,3 +19,7 @@ Gemfile.lock
19
19
  # Ignore byebug history
20
20
 
21
21
  .byebug_history
22
+
23
+ # Ignore built .gem s
24
+
25
+ *.gem
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.1.0...HEAD
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
+ [![Gem Version](https://badge.fury.io/rb/middlegem.svg)](https://badge.fury.io/rb/middlegem)
3
4
  [![Build Status](https://travis-ci.com/jacoblockard99/middlegem.svg?branch=master)](https://travis-ci.com/jacoblockard99/middlegem)
4
5
  [![Inline docs](http://inch-ci.org/github/jacoblockard99/middlegem.svg?branch=master)](http://inch-ci.org/github/jacoblockard99/middlegem)
5
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/b43ed85211cb562678bb/maintainability)](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.include?(middleware.class)
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| m.instance_of?(klass) }
145
+ middlewares.select { |m| matches_class?(m, klass) }
130
146
  end
131
147
  end
132
148
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Middlegem
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
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.1.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-09 00:00:00.000000000 Z
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: