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

Version Path
roda-3.18.0 lib/roda/plugins/delay_build.rb
roda-3.17.0 lib/roda/plugins/delay_build.rb
roda-3.16.0 lib/roda/plugins/delay_build.rb
roda-3.15.0 lib/roda/plugins/delay_build.rb
roda-3.14.1 lib/roda/plugins/delay_build.rb
roda-3.14.0 lib/roda/plugins/delay_build.rb
roda-3.13.0 lib/roda/plugins/delay_build.rb
roda-3.12.0 lib/roda/plugins/delay_build.rb
roda-3.11.0 lib/roda/plugins/delay_build.rb
roda-3.10.0 lib/roda/plugins/delay_build.rb
roda-3.9.0 lib/roda/plugins/delay_build.rb
roda-3.8.0 lib/roda/plugins/delay_build.rb
roda-3.7.0 lib/roda/plugins/delay_build.rb
roda-3.6.0 lib/roda/plugins/delay_build.rb
roda-3.5.0 lib/roda/plugins/delay_build.rb
roda-3.4.0 lib/roda/plugins/delay_build.rb
roda-3.3.0 lib/roda/plugins/delay_build.rb
roda-3.2.0 lib/roda/plugins/delay_build.rb
roda-3.1.0 lib/roda/plugins/delay_build.rb
roda-3.0.0 lib/roda/plugins/delay_build.rb