Class: Raw::Dispatcher::Mounter

Inherits:
Object
  • Object
show all
Defined in:
lib/raw/dispatcher/mounter.rb

Overview

A Helper class used for CherryPy-style publishing. This is the prefered way to mount (publish) controllers to paths as it automatically defines a controller hierarchy.

Instance Method Summary collapse

Constructor Details

#initialize(dispatcher, parent) ⇒ Mounter

:nodoc: all



13
14
15
# File 'lib/raw/dispatcher/mounter.rb', line 13

def initialize(dispatcher, parent)
  @dispatcher, @parent = dispatcher, parent
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/raw/dispatcher/mounter.rb', line 17

def method_missing(sym, *args)
  name = sym.to_s
  if name =~ /=$/
    name = name.chop
    if controller = args.first
      # Store the hierarchical parent of this controller.
      # Useful for sitemaps etc.
      controller.ann(:self, :parent => @parent)
      @dispatcher[path(name)] = controller
    end
  else
    if controller = @dispatcher[path(name)]
      Mounter.new(@dispatcher, controller)
    end
  end
end

Instance Method Details

#path(name) ⇒ Object



34
35
36
# File 'lib/raw/dispatcher/mounter.rb', line 34

def path(name)
  "#{@parent.mount_path}/#{name}".squeeze("/")
end