Sha256: 80f22ba36770a565a356214cb05d56c9b609c8f36d0785ff2a56b2f1133c1980

Contents?: true

Size: 1010 Bytes

Versions: 6

Compression:

Stored size: 1010 Bytes

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # Internal after hook module, not for external use.
    # Allows for plugins to configure the order in which
    # after processing is done by using _roda_after_*
    # private instance methods that are called in sorted order.
    module AfterHook # :nodoc:
      module ClassMethods
        # Rebuild the _roda_after method whenever a plugin might
        # have added a _roda_after_* method.
        def include(*)
          res = super
          meths = private_instance_methods.grep(/\A_roda_after_\d\d/).sort.map{|s| "#{s}(res)"}.join(';')
          class_eval("def _roda_after(res); #{meths} end", __FILE__, __LINE__)
          private :_roda_after
          res
        end
      end

      module InstanceMethods
        # Run internal after hooks with the response
        def call
          res = super
        ensure
          _roda_after(res)
        end
      end
    end

    register_plugin(:_after_hook, AfterHook)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
roda-3.16.0 lib/roda/plugins/_after_hook.rb
roda-3.15.0 lib/roda/plugins/_after_hook.rb
roda-3.14.1 lib/roda/plugins/_after_hook.rb
roda-3.14.0 lib/roda/plugins/_after_hook.rb
roda-3.13.0 lib/roda/plugins/_after_hook.rb
roda-3.12.0 lib/roda/plugins/_after_hook.rb