Class: Flame::Router::RouteRefine

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

Overview

Helper class for controller routing refine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router, ctrl, path, block) ⇒ RouteRefine

Returns a new instance of RouteRefine.



73
74
75
76
77
78
79
# File 'lib/flame/router.rb', line 73

def initialize(router, ctrl, path, block)
	@router = router
	@ctrl = ctrl
	@path = path || @ctrl.default_path
	@routes = []
	execute(&block)
end

Instance Attribute Details

#ctrlObject (readonly)

Returns the value of attribute ctrl.



60
61
62
# File 'lib/flame/router.rb', line 60

def ctrl
  @ctrl
end

#rest_routesObject

Defaults REST routes (methods, pathes, controllers actions)



63
64
65
# File 'lib/flame/router.rb', line 63

def rest_routes
  @rest_routes
end

#routesObject (readonly)

Returns the value of attribute routes.



60
61
62
# File 'lib/flame/router.rb', line 60

def routes
  @routes
end

Instance Method Details

#defaultsObject

Assign remaining methods of the controller

to defaults pathes and HTTP methods


112
113
114
115
116
117
118
# File 'lib/flame/router.rb', line 112

def defaults
	rest
	@ctrl.actions.each do |action|
		next if find_route_index(action: action)
		send(:GET.downcase, action)
	end
end

#mount(ctrl, path = nil) { ... } ⇒ Object

Mount controller inside other (parent) controller

Parameters:

  • ctrl (Flame::Controller)

    class of mounting controller

  • path (String, nil) (defaults to: nil)

    root path for mounting controller

Yields:

  • Block of code for routes refine



134
135
136
137
# File 'lib/flame/router.rb', line 134

def mount(ctrl, path = nil, &block)
	path = Flame::Path.merge(@path, path || ctrl.default_path)
	@router.add_controller(ctrl, path, &block)
end

#restObject

Assign methods of the controller to REST architecture



121
122
123
124
125
126
127
128
# File 'lib/flame/router.rb', line 121

def rest
	rest_routes.each do |rest_route|
		action = rest_route[:action]
		next if !@ctrl.actions.include?(action) ||
		        find_route_index(action: action)
		send(*rest_route.values.map(&:downcase))
	end
end