Compare commits

...

3 Commits

Author SHA1 Message Date
Charlie Somerville
dbe129af02 compile helpers without trace instruction 2013-10-16 19:54:42 -04:00
Charlie Somerville
bf71aa30d2 fast 2013-10-15 15:07:23 -04:00
Charlie Somerville
0928c2bf4f automatically infer file/line of module eval from caller 2013-10-15 15:05:32 -04:00

View File

@@ -138,8 +138,13 @@ module ActionController
end
end
def named_helper_module_eval(code, *args)
@module.module_eval(code, *args)
def named_helper_module_eval(code)
file, line = caller.first.split(":")
compile_option = RubyVM::InstructionSequence.compile_option
RubyVM::InstructionSequence.compile_option = compile_option.merge(:trace_instruction => false)
@module.module_eval(code, file, line.to_i + 1)
ensure
RubyVM::InstructionSequence.compile_option = compile_option
end
def define_hash_access(route, name, kind, options)
@@ -196,6 +201,40 @@ module ActionController
protected :#{selector} # protected :users_url
end_eval
helpers << selector
if kind == :path
define_fast_url_helper(selector, route, name)
end
end
def define_fast_url_helper(selector, route, name)
dynamic_segments = route.segments.grep(DynamicSegment)
return if dynamic_segments.any?(&:optional?) # TODO - maybe exclude optional format
helper_arguments = dynamic_segments.map { |route_argument|
"arg_#{route_argument.key}"
}
route_segments = route.segments.dup
if route_segments.size > 1 && route_segments.last.is_a?(DividerSegment) && route_segments.last.optional?
route_segments.pop
end
string_segments = route_segments.map { |segment|
if segment.is_a?(StaticSegment)
segment.value.inspect
else
'"#{URI::DEFAULT_PARSER.escape(arg_%s.to_s, ActionController::Routing::Segment::UNSAFE_PCHAR)}"' % segment.key
end
}
named_helper_module_eval <<-"RUBY"
def fast_#{selector}(#{helper_arguments.join(", ")})
#{string_segments.join(" ")}
end
RUBY
end
end