module Roda::RodaPlugins::HostRouting
def self.configure(app, opts=OPTS, &block)
:scope_predicates :: Setup predicate methods in route block scope
configure the plugin. Options:
Setup the host routing support. The block yields an object used to
def self.configure(app, opts=OPTS, &block) hosts, host_hash, default_block, default_host = DSL.new.process(&block) app.opts[:host_routing_hash] = host_hash app.opts[:host_routing_default_host] = default_host app.send(:define_method, :_host_routing_default, &default_block) if default_block app::RodaRequest.class_exec do hosts.each do |host| host_sym = host.to_sym define_method(host_sym){|&blk| always(&blk) if _host_routing_host == host} alias_method host_sym, host_sym meth = :"#{host}?" define_method(meth){_host_routing_host == host} alias_method meth, meth end end if opts[:scope_predicates] app.class_exec do hosts.each do |host| meth = :"#{host}?" define_method(meth){@_request.send(meth)} alias_method meth, meth end end end end