class Roda::RodaPlugins::HostRouting::DSL
Public Class Methods
Source
# File lib/roda/plugins/host_routing.rb, line 110 def initialize @hosts = [] @host_hash = {} end
Public Instance Methods
Source
# File lib/roda/plugins/host_routing.rb, line 147 def default(hostname, &block) @default_host = hostname @default_block = block end
Register the default hostname. If a block is provided, it is called with the host if there is no match for one of the hostnames provided to to
. If the block returns nil/false, the hostname given to this method is used.
Source
# File lib/roda/plugins/host_routing.rb, line 116 def process(&block) instance_exec(self, &block) if !@default_host raise RodaError, "must call default method inside host_routing plugin block to set default host" end @hosts.concat(@host_hash.values) @hosts << @default_host @hosts.uniq! [@hosts.freeze, @host_hash.freeze, @default_block, @default_host].freeze end
Run the DSL
for the given block.
Source
# File lib/roda/plugins/host_routing.rb, line 132 def register(*hosts) @hosts = hosts end
Register hosts that can be returned. This is only needed if calling register with a block, where the block can return a value that doesn’t match a host given to to
or default
.
Source
# File lib/roda/plugins/host_routing.rb, line 137 def to(host, *hostnames) hostnames.each do |hostname| @host_hash[hostname] = host end end
Treat all given hostnames as routing to the give host.