Class: Usher::Interface::Rails23::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/usher/interface/rails23/mapper.rb

Overview

:doc:

Instance Method Summary collapse

Constructor Details

#initialize(set) ⇒ Mapper

:nodoc:



6
7
8
# File 'lib/usher/interface/rails23/mapper.rb', line 6

def initialize(set) #:nodoc:
  @set = set
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(route_name, *args, &proc) ⇒ Object

:nodoc:



36
37
38
39
# File 'lib/usher/interface/rails23/mapper.rb', line 36

def method_missing(route_name, *args, &proc) #:nodoc:
  super unless args.length >= 1 && proc.nil?
  @set.add_named_route(route_name, *args)
end

Instance Method Details

#connect(path, options = {}) ⇒ Object



10
11
12
# File 'lib/usher/interface/rails23/mapper.rb', line 10

def connect(path, options = {})
  @set.add_route(path, options)
end

#named_route(name, path, options = nil) ⇒ Object



24
25
26
# File 'lib/usher/interface/rails23/mapper.rb', line 24

def named_route(name, path, options = nil)
  @set.add_named_route(name, path, options)
end

#namespace(name, options = {}, &block) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/usher/interface/rails23/mapper.rb', line 28

def namespace(name, options = {}, &block)
  if options[:namespace]
    with_options({:path_prefix => "#{options.delete(:path_prefix)}/#{name}", :name_prefix => "#{options.delete(:name_prefix)}#{name}_", :namespace => "#{options.delete(:namespace)}#{name}/" }.merge(options), &block)
  else
    with_options({:path_prefix => name, :name_prefix => "#{name}_", :namespace => "#{name}/" }.merge(options), &block)
  end
end

#root(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/usher/interface/rails23/mapper.rb', line 14

def root(options = {})
  if options.is_a?(Symbol)
    if source_route = @set.named_routes[options]
      options = source_route.conditions.blank? ? 
        source_route.options.merge({ :conditions => source_route.conditions }) : source_route.options
    end
  end
  named_route(:root, '/', options)
end