X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=vendor%2Frails%2Factionpack%2Flib%2Faction_controller%2Frouting%2Frouting_ext.rb;fp=vendor%2Frails%2Factionpack%2Flib%2Faction_controller%2Frouting%2Frouting_ext.rb;h=4a82b2af5f63dbab98b528a6a60ea2b417165c12;hb=d115f2e23823271635bad69229a42cd8ac68debe;hp=0000000000000000000000000000000000000000;hpb=37cb670bf3ddde90b214e591f100ed4446469484;p=depot.git diff --git a/vendor/rails/actionpack/lib/action_controller/routing/routing_ext.rb b/vendor/rails/actionpack/lib/action_controller/routing/routing_ext.rb new file mode 100644 index 0000000..4a82b2a --- /dev/null +++ b/vendor/rails/actionpack/lib/action_controller/routing/routing_ext.rb @@ -0,0 +1,49 @@ +class Object + def to_param + to_s + end +end + +class TrueClass + def to_param + self + end +end + +class FalseClass + def to_param + self + end +end + +class NilClass + def to_param + self + end +end + +class Regexp #:nodoc: + def number_of_captures + Regexp.new("|#{source}").match('').captures.length + end + + def multiline? + options & MULTILINE == MULTILINE + end + + class << self + def optionalize(pattern) + case unoptionalize(pattern) + when /\A(.|\(.*\))\Z/ then "#{pattern}?" + else "(?:#{pattern})?" + end + end + + def unoptionalize(pattern) + [/\A\(\?:(.*)\)\?\Z/, /\A(.|\(.*\))\?\Z/].each do |regexp| + return $1 if regexp =~ pattern + end + return pattern + end + end +end