Public Class methods
new()
[show source]
# File lib/roda/plugins/host_routing.rb 110 def initialize 111 @hosts = [] 112 @host_hash = {} 113 end
Public Instance methods
default(hostname, &block)
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.
[show source]
# File lib/roda/plugins/host_routing.rb 147 def default(hostname, &block) 148 @default_host = hostname 149 @default_block = block 150 end
process(&block)
Run the DSL
for the given block.
[show source]
# File lib/roda/plugins/host_routing.rb 116 def process(&block) 117 instance_exec(self, &block) 118 119 if !@default_host 120 raise RodaError, "must call default method inside host_routing plugin block to set default host" 121 end 122 123 @hosts.concat(@host_hash.values) 124 @hosts << @default_host 125 @hosts.uniq! 126 [@hosts.freeze, @host_hash.freeze, @default_block, @default_host].freeze 127 end
register(*hosts)
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
.
[show source]
# File lib/roda/plugins/host_routing.rb 132 def register(*hosts) 133 @hosts = hosts 134 end
to(host, *hostnames)
Treat all given hostnames as routing to the give host.
[show source]
# File lib/roda/plugins/host_routing.rb 137 def to(host, *hostnames) 138 hostnames.each do |hostname| 139 @host_hash[hostname] = host 140 end 141 end