0
- def number_of_captures
0
- Regexp.new("|#{source}").match('').captures.length
0
- def optionalize(pattern)
0
- case unoptionalize(pattern)
0
- when /\A(.|\(.*\))\Z/ then "#{pattern}?"
0
- else "(?:#{pattern})?"
0
- def unoptionalize(pattern)
0
- [/\A\(\?:(.*)\)\?\Z/, /\A(.|\(.*\))\?\Z/].each do |regexp|
0
- return $1 if regexp =~ pattern
0
module ActionController
0
- SEPARATORS = %w( / ; . , ? )
0
+ module Routing #:nodoc:
0
- def with_controllers(names)
0
- use_controllers! names
0
+ def expiry_hash(options, recall)
0
+ options.each {|k, v| expire_on[k] = ((rcv = recall[k]) && (rcv != v))}
0
- def normalize_paths(paths = $LOAD_PATH)
0
- # do the hokey-pokey of path normalization...
0
- paths = paths.collect do |path|
0
- gsub("//", "/"). # replace double / chars with a single
0
- gsub("\\\\", "\\"). # replace double \ chars with a single
0
- gsub(%r{(.)[\\/]$}, '\1') # drop final / or \ if path ends with it
0
- # eliminate .. paths where possible
0
- re = %r{\w+[/\\]\.\.[/\\]}
0
- path.gsub!(%r{\w+[/\\]\.\.[/\\]}, "") while path.match(re)
0
- # start with longest path, first
0
- paths = paths.uniq.sort_by { |path| - path.length }
0
+ def extract_parameter_value(parameter) #:nodoc:
0
+ CGI.escape((parameter.respond_to?(:to_param) ? parameter.to_param : parameter).to_s)
0
- def possible_controllers
0
- unless @possible_controllers
0
- @possible_controllers = []
0
- paths = $LOAD_PATH.select { |path| File.directory?(path) && path != "." }
0
- seen_paths = Hash.new {|h, k| h[k] = true; false}
0
- normalize_paths(paths).each do |load_path|
0
- Dir["#{load_path}/**/*_controller.rb"].collect do |path|
0
- next if seen_paths[path.gsub(%r{^\.[/\\]}, "")]
0
- controller_name = path[(load_path.length + 1)..-1]
0
- next unless path_may_be_controller?(controller_name)
0
- controller_name.gsub!(/_controller\.rb\Z/, '')
0
- @possible_controllers << controller_name
0
- @possible_controllers.uniq!
0
- def path_may_be_controller?(path)
0
- path !~ /(?:rails\/.*\/(?:examples|test))|(?:actionpack\/lib\/action_controller.rb$)|(?:app\/controllers)/o
0
- def use_controllers!(controller_names)
0
- @possible_controllers = controller_names
0
def controller_relative_to(controller, previous)
0
if controller.nil? then previous
0
elsif controller[0] == ?/ then controller[1..-1]
0
elsif %r{^(.*)/} =~ previous then "#{$1}/#{controller}"
0
- attr_accessor :segments, :requirements, :conditions
0
- # Write and compile a +generate+ method for this Route.
0
- # Build the main body of the generation
0
- body = "not_expired = true\n#{generation_extraction}\n#{generation_structure}"
0
- # If we have conditions that must be tested first, nest the body inside an if
0
- body = "if #{generation_requirements}\n#{body}\nend" if generation_requirements
0
- args = "options, hash, expire_on = {}"
0
- # Nest the body inside of a def block, and then compile it.
0
- raw_method = method_decl = "def generate_raw(#{args})\npath = begin\n#{body}\nend\n[path, hash]\nend"
0
- instance_eval method_decl, "generated code (#{__FILE__}:#{__LINE__})"
0
- # expire_on.keys == recall.keys; in other words, the keys in the expire_on hash
0
- # are the same as the keys that were recalled from the previous request. Thus,
0
- # we can use the expire_on.keys to determine which keys ought to be used to build
0
- # the query string. (Never use keys from the recalled request when building the
0
- method_decl = "def generate(#{args})\npath, hash = generate_raw(options, hash, expire_on)\nappend_query_string(path, hash, extra_keys(hash, expire_on))\nend"
0
- instance_eval method_decl, "generated code (#{__FILE__}:#{__LINE__})"
0
- method_decl = "def generate_extras(#{args})\npath, hash = generate_raw(options, hash, expire_on)\n[path, extra_keys(hash, expire_on)]\nend"
0
- instance_eval method_decl, "generated code (#{__FILE__}:#{__LINE__})"
0
- # Build several lines of code that extract values from the options hash. If any
0
- # of the values are missing or rejected then a return will be executed.
0
- def generation_extraction
0
- segments.collect do |segment|
0
- segment.extraction_code
0
- # Produce a condition expression that will check the requirements of this route
0
- def generation_requirements
0
- requirement_conditions = requirements.collect do |key, req|
0
- value_regexp = Regexp.new "\\A#{req.source}\\Z"
0
- "hash[:#{key}] && #{value_regexp.inspect} =~ options[:#{key}]"
0
+ def treat_hash(hash, keys_to_delete = [])
0
+ if v then hash[k] = (v.respond_to? :to_param) ? v.to_param.to_s : v.to_s
0
- "hash[:#{key}] == #{req.inspect}"
0
-
requirement_conditions * ' && ' unless requirement_conditions.empty?0
- def generation_structure
0
- segments.last.string_structure segments[0..-2]