Public Class methods
new()
[show source]
# File lib/roda/plugins/host_routing.rb 112 def initialize 113 @hosts = [] 114 @host_hash = {} 115 @default_host = nil 116 @default_block = nil 117 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 151 def default(hostname, &block) 152 @default_host = hostname 153 @default_block = block 154 end
process(&block)
Run the DSL for the given block.
[show source]
# File lib/roda/plugins/host_routing.rb 120 def process(&block) 121 instance_exec(self, &block) 122 123 if !@default_host 124 raise RodaError, "must call default method inside host_routing plugin block to set default host" 125 end 126 127 @hosts.concat(@host_hash.values) 128 @hosts << @default_host 129 @hosts.uniq! 130 [@hosts.freeze, @host_hash.freeze, @default_block, @default_host].freeze 131 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 136 def register(*hosts) 137 @hosts = hosts 138 end
to(host, *hostnames)
Treat all given hostnames as routing to the give host.
[show source]
# File lib/roda/plugins/host_routing.rb 141 def to(host, *hostnames) 142 hostnames.each do |hostname| 143 @host_hash[hostname] = host 144 end 145 end