class Flame::Router::RouteRefine

Helper class for controller routing refine

Attributes

ctrl[R]
rest_routes[RW]
routes[R]

Public Class Methods

new(router, ctrl, path, block) click to toggle source
# 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

Public Instance Methods

defaults() click to toggle source

Assign remaining methods of the controller

to defaults pathes and HTTP methods
# 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, &block) click to toggle source

Mount controller inside other (parent) controller @param ctrl [Flame::Controller] class of mounting controller @param path [String, nil] root path for mounting controller @yield Block of code for routes refine

# 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
rest() click to toggle source

Assign methods of the controller to REST architecture

# 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

Private Instance Methods

execute(&block) click to toggle source

Execute block of refinings end sorting routes

# File lib/flame/router.rb, line 142
def execute(&block)
        instance_exec(&block) if block
        defaults
        @routes.sort!
end
find_route_index(attrs) click to toggle source
# File lib/flame/router.rb, line 148
def find_route_index(attrs)
        @routes.find_index { |route| route.compare_attributes(attrs) }
end