Class: Junior::Usher

Inherits:
Object
  • Object
show all
Defined in:
lib/junior/router.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUsher

Returns a new instance of Usher.



26
27
28
# File 'lib/junior/router.rb', line 26

def initialize
  @router = ::Usher::Interface.for(:rack, nil, :use_destinations => false)
end

Instance Attribute Details

#routerObject (readonly)

Returns the value of attribute router.



24
25
26
# File 'lib/junior/router.rb', line 24

def router
  @router
end

Class Method Details

.routes(&block) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/junior/router.rb', line 32

def routes( &block )
  usher = self.new
  
  usher.instance_eval( &block )
  
  usher.router
end

Instance Method Details

#delete(path, route) ⇒ Object



73
74
75
# File 'lib/junior/router.rb', line 73

def delete( path, route )
  self.router.delete( path ).to( route )
end

#get(path, route) ⇒ Object



61
62
63
# File 'lib/junior/router.rb', line 61

def get( path, route )
  self.router.get( path ).to( route )
end

#post(path, route) ⇒ Object



69
70
71
# File 'lib/junior/router.rb', line 69

def post( path, route )
  self.router.post( path ).to( route )
end

#put(path, route) ⇒ Object



65
66
67
# File 'lib/junior/router.rb', line 65

def put( path, route )
  self.router.put( path ).to( route )
end

#resources(resource, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/junior/router.rb', line 41

def resources( resource, &block )
  resource = "#{@parent_resource}/:#{@parent_resource}_id/#{resource}" if @parent_resource
  
  self.router.get(    "/#{resource}(.:format)"            ).to( :controller => resource, :action => 'index'   ).name( :"#{resource}_index" )
  self.router.post(   "/#{resource}(.:format)"            ).to( :controller => resource, :action => 'create'  ).name( :"#{resource}_create" )
  self.router.get(    "/#{resource}/new(.:format)"        ).to( :controller => resource, :action => 'new'     ).name( :"#{resource}_new" )
  self.router.get(    "/#{resource}/:id/edit(.:format)"   ).to( :controller => resource, :action => 'edit'    ).name( :"#{resource}_edit" )
  self.router.get(    "/#{resource}/:id/delete(.:format)" ).to( :controller => resource, :action => 'delete'  ).name( :"#{resource}_delete" )
  self.router.get(    "/#{resource}/:id(.:format)"        ).to( :controller => resource, :action => 'show'    ).name( :"#{resource}_show" )
  self.router.put(    "/#{resource}/:id(.:format)"        ).to( :controller => resource, :action => 'update'  ).name( :"#{resource}_update" )
  self.router.delete( "/#{resource}/:id(.:format)"        ).to( :controller => resource, :action => 'destroy' ).name( :"#{resource}_destroy" )
  
  if block_given?
    @parent_resource = resource
    block.call
  end
  
  @parent_resource = nil
end