class Twke::Routes::RoutePrefix

Public Class Methods

new(str = nil) click to toggle source
# File lib/twke/routes.rb, line 4
def initialize(str = nil)
  @levels = []
  @levels.push(str) if str
end

Public Instance Methods

cmd(&blk) click to toggle source

Run a raw command and the connection scope level

# File lib/twke/routes.rb, line 25
def cmd(&blk)
  Routes.cmd(&blk)
end
method_missing(name, *opts) { || ... } click to toggle source
# File lib/twke/routes.rb, line 29
def method_missing(name, *opts, &blk)
  if no_prefix?(*opts)
    # If they requested no prefix, save the current prefix
    # and execute the block starting with the current prefix
    save_levels = @levels.dup
    @levels = [name]
    yield
    @levels = save_levels
  else
    @levels.push(name)
    yield
    @levels.pop
  end
end
route(trigger, *opts, &blk) click to toggle source
# File lib/twke/routes.rb, line 9
def route(trigger, *opts, &blk)
  if trigger.class == Regexp
    if prefix.length > 0 && !no_prefix?(*opts)
      trigger = Regexp.new("#{prefix} #{trigger.to_s}")
    end

    Routes.add(trigger, *opts, &blk)
  else
    # Send trigger as a prefix
    self.send(trigger, *opts) do
      Routes.add(prefix, *opts, &blk)
    end
  end
end

Private Instance Methods

no_prefix?(options = {}) click to toggle source
# File lib/twke/routes.rb, line 46
def no_prefix?(options = {})
  options[:noprefix]
end
prefix() click to toggle source
# File lib/twke/routes.rb, line 50
def prefix
  @levels.join(" ")
end