Class: ActionController::Routing::RouteSet::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/support/route_mapper.rb

Overview

For use with ‘Edge Rails’

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



40
41
42
43
44
45
46
47
48
49
# File 'lib/support/route_mapper.rb', line 40

def method_missing( name, *args, &proc )
  if name.to_s.starts_with?( 'comatose_' )
    opts = (args.last.is_a?(Hash)) ? args.pop : {}
    opts[:named_route] = name.to_s #[9..-1]
    comatose_root( *(args << opts) )
  else
    super unless args.length >= 1 && proc.nil?
    @set.add_named_route(name, *args)
  end
end

Instance Method Details

#comatose_admin(path = 'comatose_admin', options = {}) ⇒ Object

For mounting the admin



31
32
33
34
35
36
37
38
# File 'lib/support/route_mapper.rb', line 31

def comatose_admin( path='comatose_admin', options={} )
  opts = {
    :controller  => 'comatose_admin',
    :named_route => 'comatose_admin'
  }.merge(options)
  route_name = opts.delete(:named_route)
  named_route( route_name, "#{path}/:action/:id", opts )
end

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

For mounting a page to a path



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/support/route_mapper.rb', line 5

def comatose_root( path, options={} )
  opts = {
    :index      => '',
    :layout     => 'comatose_content.html.erb',
    :use_cache  => 'true',
    :cache_path => nil,
    :named_route=> nil
  }.merge(options)
  # Ensure the controller is aware of the mount point...
  Comatose.add_mount_point(path, opts)
  # Add the route...
  opts[:controller] = 'comatose'
  opts[:action] ='show'
  route_name = opts.delete(:named_route)
  unless route_name.nil?
    named_route( route_name, "#{path}/*page", opts )
  else
    if opts[:index] == '' # if it maps to the root site URI, name it comatose_root
      named_route( 'comatose_root', "#{path}/*page", opts )
    else
      connect( "#{path}/*page", opts )
    end
  end
end