Sha256: 4efb6b157942c02272beffc578d4898896e7c3bdda6051948b635683017b7281
Contents?: true
Size: 1.25 KB
Versions: 39
Compression:
Stored size: 1.25 KB
Contents
# frozen-string-literal: true # class Roda module RodaPlugins # The delay_build plugin does not build the rack app until # Roda.app is called, and only rebuilds the rack app if Roda.build! # is called. This differs from Roda's default behavior, which # rebuilds the rack app every time the route block changes and # every time middleware is added if a route block has already # been defined. # # If you are loading hundreds of middleware after a # route block has already been defined, this can fix a possible # performance issue, turning an O(n^2) calculation into an # O(n) calculation, where n is the number of middleware used. module DelayBuild module ClassMethods # If the app is not been defined yet, build the app. def app @app || build! end # Rebuild the application. def build! @build_app = true build_rack_app @app ensure @build_app = false end private # Do not build the rack app automatically, wait for an # explicit call to build!. def build_rack_app super if @build_app end end end register_plugin(:delay_build, DelayBuild) end end
Version data entries
39 entries across 39 versions & 1 rubygems