Class: ReplIndex
Class Method Summary collapse
Instance Method Summary collapse
- #add_all_loaded! ⇒ Object
- #add_file(f) ⇒ Object
- #find(strs, ops = {}) ⇒ Object
- #globs ⇒ Object
- #green(*args) ⇒ Object
- #include_file_in_search?(f, ops) ⇒ Boolean
- #open!(f) ⇒ Object
- #red(*args) ⇒ Object
Class Method Details
.fcf(*args) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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) ⇒ Object
7 8 9 |
# File 'lib/repl_index.rb', line 7 def method_missing(sym,*args,&b) instance.send(sym,*args,&b) end |
Instance Method Details
#add_all_loaded! ⇒ Object
41 42 43 |
# File 'lib/repl_index.rb', line 41 def add_all_loaded! $".each { |f| add_file(f) } end |
#add_file(f) ⇒ Object
35 36 37 38 39 40 |
# 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 = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
21 22 23 24 |
# File 'lib/repl_index.rb', line 21 def globs ext_str = "{" + exts.join(",") + "}" dirs.map { |dir| "#{dir}/**/*.#{ext_str}" } + addl_globs end |
#green(*args) ⇒ Object
63 |
# File 'lib/repl_index.rb', line 63 def green(*args); puts(*args); end |
#include_file_in_search?(f, ops) ⇒ Boolean
44 45 46 47 |
# 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) ⇒ Object
57 58 59 60 61 62 |
# 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) ⇒ Object
64 |
# File 'lib/repl_index.rb', line 64 def red(*args); puts(*args); end |