Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 9adb6c5796
Fetching contributors…

Cannot retrieve contributors at this time

executable file 26 lines (23 sloc) 1.027 kB
# place it before modules + symbols
complete(:on=>/(?:(?:[a-zA-Z]\w*):)+(\w+)?$/, :search=>false, :action=>:alias_constants, :place=>4)
recomplete(:name=>:constants, :anywhere=>'([A-Z][^. \(]*)::([^: .]*)') {|e|
receiver = e.matched[2]
candidates = eval("#{receiver}.constants") || []
normal_search(e.matched[3], candidates).map {|e| "#{receiver}::#{e}" }
}
def alias_constants(input)
fetch_constants = proc {|klass, klass_alias| klass.constants.grep(/^#{klass_alias}/i).map {|f| klass.const_get(f)} }
fetch_string_constants = proc {|klass, klass_alias|
klass.constants.grep(/^#{klass_alias}/i).map {|f|
(val = klass.const_get(f)) && val.is_a?(Module) ? val.to_s : "#{klass}::#{f}"
}
}
index = 1
aliases = input.split(":")
aliases.inject([Object]) do |completions,a|
completions = completions.select {|e| e.is_a?(Module) }.map {|klass|
aliases.size != index ? fetch_constants.call(klass, a) : fetch_string_constants.call(klass, a)
}.flatten
index += 1; completions
end
end
Jump to Line
Something went wrong with that request. Please try again.