Skip to content

Instantly share code, notes, and snippets.

@julian7
Created February 6, 2010 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julian7/296725 to your computer and use it in GitHub Desktop.
Save julian7/296725 to your computer and use it in GitHub Desktop.
ike:~>>% ruby -e 'puts $".grep(/rubygems/)'
/Users/js/.rvm/rubies/ruby-1.9.1-p378/lib/ruby/1.9.1/rubygems.rb
module ActionDispatch
module Routing
class Mapper
...
module Resources
...
private
...
def save_scope
{
:path => @scope[:path],
:name_prefix => @scope[:name_prefix]
}
end
def restore_scope(hsh)
@scope[:path] = hsh[:path]
@scope[:name_prefix] = hsh[:name_prefix]
end
def with_shallow_scope(curr_scope)
if !block_given?
raise 'with_shallow_scope expects a block'
end
_saved_scope = save_scope
shallow_scope(curr_scope)
yield
restore_scope(_saved_scope)
end
def shallow_scope(ref_scope)
return if ref_scope.nil?
return unless @scope.has_key? :shallow
root_scope = @scope[:shallow]
return if root_scope[:path] == ref_scope[:path]
pathstart = namestart = 0
unless @scope[:path].start_with? ref_scope[:path]
raise 'shallow_scope path mismatch'
end
pathstop, namestop = ref_scope[:path].length-1, ref_scope[:name_prefix].length-1
if @scope[:path].start_with? root_scope[:path]
pathstart, namestart = root_scope[:path].length, root_scope[:name_prefix].length
end
@scope[:path] = @scope[:path].dup
@scope[:path][pathstart..pathstop] = ''
@scope[:name_prefix] = @scope[:name_prefix].dup
@scope[:name_prefix][namestart..namestop] = ''
end
end
...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment