class Roda::RodaPlugins::HostRouting::DSL

  1. lib/roda/plugins/host_routing.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. default
  2. process
  3. register
  4. to

Public Class methods

new()
[show source]
    # File lib/roda/plugins/host_routing.rb
133 def initialize
134   @hosts = []
135   @host_hash = {}
136   @default_host = nil
137   @default_block = nil
138 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
172 def default(hostname, &block)
173   @default_host = hostname
174   @default_block = block
175 end
process(&block)

Run the DSL for the given block.

[show source]
    # File lib/roda/plugins/host_routing.rb
141 def process(&block)
142   instance_exec(self, &block)
143 
144   if !@default_host
145     raise RodaError, "must call default method inside host_routing plugin block to set default host"
146   end
147 
148   @hosts.concat(@host_hash.values)
149   @hosts << @default_host
150   @hosts.uniq!
151   [@hosts.freeze, @host_hash.freeze, @default_block, @default_host].freeze
152 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
157 def register(*hosts)
158   @hosts = hosts
159 end
to(host, *hostnames)

Treat all given hostnames as routing to the give host.

[show source]
    # File lib/roda/plugins/host_routing.rb
162 def to(host, *hostnames)
163   hostnames.each do |hostname|
164     @host_hash[hostname.downcase.freeze] = host
165   end
166 end