module Roda::RodaPlugins::Hooks::ClassMethods

  1. lib/roda/plugins/hooks.rb

Methods

Public Instance

  1. after
  2. before
  3. freeze

Public Instance methods

after(&block)

Add an after hook.

[show source]
   # File lib/roda/plugins/hooks.rb
51 def after(&block)
52   opts[:after_hooks] << define_roda_method("after_hook", 1, &block)
53   if opts[:after_hooks].length == 1
54     class_eval("alias _roda_after_80__hooks #{opts[:after_hooks].first}", __FILE__, __LINE__)
55   else
56     class_eval("def _roda_after_80__hooks(res) #{opts[:after_hooks].map{|m| "#{m}(res)"}.join(';')} end", __FILE__, __LINE__)
57   end
58   private :_roda_after_80__hooks
59   def_roda_after
60   nil
61 end
before(&block)

Add a before hook.

[show source]
   # File lib/roda/plugins/hooks.rb
64 def before(&block)
65   opts[:before_hooks].unshift(define_roda_method("before_hook", 0, &block))
66   if opts[:before_hooks].length == 1
67     class_eval("alias _roda_before_10__hooks #{opts[:before_hooks].first}", __FILE__, __LINE__)
68   else
69     class_eval("def _roda_before_10__hooks; #{opts[:before_hooks].join(';')} end", __FILE__, __LINE__)
70   end
71   private :_roda_before_10__hooks
72   def_roda_before
73   nil
74 end
freeze()

Freeze the array of hook methods when freezing the app.

[show source]
   # File lib/roda/plugins/hooks.rb
43 def freeze
44   opts[:after_hooks].freeze
45   opts[:before_hooks].freeze
46 
47   super
48 end