class ReplIndex

Public Class Methods

fcf(*args) click to toggle source
# File lib/repl_index.rb, line 67
def fcf(*args)
  ops = args.last.kind_of?(Hash) ? args.pop : {}
  strs = [args].flatten.map { |x| x.to_s }
  add_all_loaded!
  files = ReplIndex.find(strs,ops)
  puts "\n#{green(files.size.to_s)} matches for #{green(strs.inspect)}"
  files.each_with_index { |x,i| puts "#{i+1}. #{x}" }
  puts "\n"

  if ops[:choose]
    i = STDIN.gets.to_i
    ReplIndex.open! files[i-1] if i > 0
  end

  nil
end
method_missing(sym,*args,&b) click to toggle source
# File lib/repl_index.rb, line 7
def method_missing(sym,*args,&b)
  instance.send(sym,*args,&b)
end

Public Instance Methods

add_all_loaded!() click to toggle source
# File lib/repl_index.rb, line 41
def add_all_loaded!
  $".each { |f| add_file(f) }
end
add_file(f) click to toggle source
# File lib/repl_index.rb, line 35
def add_file(f)
  f = f.downcase
  return if bodies[f]
  return unless f =~ /\.rb$/i || f =~ /rake/i
  bodies[f] = File.read(f)
end
find(strs,ops={}) click to toggle source
# File lib/repl_index.rb, line 48
def find(strs,ops={})
  res = []
  strs = [strs].flatten
  bodies.each do |f,body|
    res << f if strs.all? { |str| include_file_in_search?(f,ops) && (f =~ /#{str}/i || body =~ /#{str}/i) }
  end
  #res#.map { |x| x.gsub("#{dir}","CB") }
  res
end
globs() click to toggle source
# File lib/repl_index.rb, line 21
def globs
  ext_str = "{" + exts.join(",") + "}"
  dirs.map { |dir| "#{dir}/**/*.#{ext_str}" } + addl_globs
end
green(*args) click to toggle source
# File lib/repl_index.rb, line 63
def green(*args); puts(*args); end
include_file_in_search?(f,ops) click to toggle source
# File lib/repl_index.rb, line 44
def include_file_in_search?(f,ops)
  return false if ops[:ext] && f.split(".").last.downcase != ops[:ext].to_s.downcase
  true
end
open!(f) click to toggle source
# File lib/repl_index.rb, line 57
def open!(f)
  #cmd = "\"c:\\progra~1\\sublime text 2\\sublime_text.exe\" #{f}"
  #ec cmd
  dir = File.dirname(f).gsub("/","\\")
  `explorer "#{dir}"`
end
red(*args) click to toggle source
# File lib/repl_index.rb, line 64
def red(*args); puts(*args); end