Module: Roda::RodaPlugins::MatchHookArgs::ClassMethods

Defined in:
lib/roda/plugins/match_hook_args.rb

Instance Method Summary collapse

Instance Method Details

#add_match_hook(&block) ⇒ Object

Add a match hook that will be called with matchers and block args.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/roda/plugins/match_hook_args.rb', line 50

def add_match_hook(&block)
  opts[:match_hook_args] << define_roda_method("match_hook_args", :any, &block)

  if opts[:match_hook_args].length == 1
    class_eval("alias _match_hook_args #{opts[:match_hook_args].first}", __FILE__, __LINE__)
  else
    class_eval("def _match_hook_args(v, a); #{opts[:match_hook_args].map{|m| "#{m}(v, a)"}.join(';')} end", __FILE__, __LINE__)
  end

  public :_match_hook_args

  nil
end

#freezeObject

Freeze the array of hook methods when freezing the app



44
45
46
47
# File 'lib/roda/plugins/match_hook_args.rb', line 44

def freeze
  opts[:match_hook_args].freeze
  super
end