Class: Jax::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/jax/routes.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load!Object



56
57
58
59
# File 'lib/jax/routes.rb', line 56

def load!
  @loaded = true
  require File.join(Jax.root, "config/routes.rb")
end

Instance Method Details

#compile(outfile) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jax/routes.rb', line 24

def compile(outfile)
  if root
    outfile.puts "Jax.routes.root(#{controller_name_for(root[0])}, #{root[1].inspect});"
  end
  map && map.each do |set|
    path = set[0]
    args = set[2..-1].collect { |s| s.inspect }.join(",")
    
    outfile.puts "Jax.routes.map(#{path.inspect}, #{controller_name_for(set[1])}, #{args});"
  end
end

#map(*args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jax/routes.rb', line 5

def map(*args, &block)
  if block_given?
    instance_eval &block
  else
    if !args.empty?
      @map ||= []
      case args.length
        when 1 then args.push(args[0], "index")
        when 2 then args.push("index")
        when 3 then ;
        else raise ArgumentError, "expected #map(path, controller_name[, action_name]), got #{args.inspect}"
      end
      @map << args
    end
  end
  @map && @map.uniq!
  @map
end

#reload!Object



43
44
45
# File 'lib/jax/routes.rb', line 43

def reload!
  load File.join(Jax.root, "config/routes.rb")
end

#root(controller = nil, action = 'index') ⇒ Object



36
37
38
39
40
41
# File 'lib/jax/routes.rb', line 36

def root(controller = nil, action = 'index')
  if controller
    @root = [controller, action]
  end
  @root
end