Module: Brakeman::RouteHelper

Included in:
Rails2RoutesProcessor, Rails3RoutesProcessor
Defined in:
lib/brakeman/processors/lib/route_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_resource_routesObject

Add default routes minus :index



55
56
57
58
59
60
61
# File 'lib/brakeman/processors/lib/route_helper.rb', line 55

def add_resource_routes
  existing_routes = @tracker.routes[@current_controller]

  unless existing_routes.is_a? Array and existing_routes.first == :allow_all_actions
    existing_routes.merge [:new, :create, :show, :edit, :update, :destroy]
  end
end

#add_resources_routesObject

Add default routes



46
47
48
49
50
51
52
# File 'lib/brakeman/processors/lib/route_helper.rb', line 46

def add_resources_routes
  existing_routes = @tracker.routes[@current_controller]

  unless existing_routes.is_a? Array and existing_routes.first == :allow_all_actions
    existing_routes.merge [:index, :new, :create, :show, :edit, :update, :destroy]
  end
end

#add_route(route, controller = nil) ⇒ Object

Add route to controller. If a controller is specified, the current controller will be set to that controller. If no controller is specified, uses current controller value.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/brakeman/processors/lib/route_helper.rb', line 27

def add_route route, controller = nil
  if node_type? route, :str, :lit
    route = route.value
  end

  route = route.to_sym

  if controller
    self.current_controller = controller
  end

  routes = @tracker.routes[@current_controller]
  
  if routes and routes != :allow_all_actions
    routes << route
  end
end

#current_controller=(name) ⇒ Object

Sets the controller name to a proper class name. For example self.current_controller = :session Also prepends the prefix if there is one set.



19
20
21
22
# File 'lib/brakeman/processors/lib/route_helper.rb', line 19

def current_controller= name
  @current_controller = (prefix + camelize(name) + "Controller").to_sym
  @tracker.routes[@current_controller] ||= Set.new
end

#prefixObject

Manage Controller prefixes suitable for prefixing onto a controller name.



5
6
7
8
9
10
11
# File 'lib/brakeman/processors/lib/route_helper.rb', line 5

def prefix
  if @prefix.length > 0
    @prefix.join("::") << "::"
  else
    ''
  end
end