forked from bridgetownrb/bridgetown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow route classes to be prioritized to adjust run order (bridgetown…
…rb#538) * Allow route classes to be prioritized to adjust run order * Add Roda/SSR integration testing — more to come! * improve route testing * fix cops * leave the plugins folder in place * fix: plugins & components folders can now be absent * Add site `server_shutdown` hook via Puma * Move routes prioritization to a concern, better documentation * Add prioritiziation feature to Builders * Add documentation for the later value
- Loading branch information
1 parent
42622c7
commit 8b0a13f
Showing
22 changed files
with
302 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
bridgetown-core/lib/bridgetown-core/concerns/prioritizable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bridgetown | ||
module Prioritizable | ||
module ClassMethods | ||
# @!method priorities | ||
# @return [Hash<Symbol, Object>] | ||
|
||
# Get or set the priority of this class. When called without an | ||
# argument it returns the priority. When an argument is given, it will | ||
# set the priority. | ||
# | ||
# @param priority [Symbol] new priority (optional) | ||
# Valid options are: `:lowest`, `:low`, `:normal`, `:high`, `:highest` | ||
# @return [Symbol] | ||
def priority(priority = nil) | ||
@priority ||= nil | ||
@priority = priority if priority && priorities.key?(priority) | ||
@priority || :normal | ||
end | ||
|
||
# Spaceship is priority [higher -> lower] | ||
# | ||
# @param other [Class] The class to be compared. | ||
# @return [Integer] -1, 0, 1. | ||
def <=>(other) | ||
priorities[other.priority] <=> priorities[priority] | ||
end | ||
end | ||
|
||
def self.included(klass) | ||
klass.extend ClassMethods | ||
klass.class_attribute :priorities, instance_accessor: false | ||
end | ||
|
||
# Spaceship is priority [higher -> lower] | ||
# | ||
# @param other [object] The object to be compared. | ||
# @return [Integer] -1, 0, 1. | ||
def <=>(other) | ||
self.class <=> other.class | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.