Class: Ruber::RI::Search

Inherits:
Object show all
Defined in:
plugins/ruberri/search.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) find_classes(drv, name)



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'plugins/ruberri/search.rb', line 80

def find_classes drv, name
  begin cls = drv.expand_class(Regexp.quote(name))
  rescue RDoc::RI::Driver::NotFoundError
    return 
  end
  stores = drv.classes[cls]
  return unless stores
  classes = []
  stores.each do |s|
    classes << [s.load_class(cls), s]
  end
  classes
end

- (Object) find_methods(drv, name)



94
95
96
97
98
99
100
101
102
103
# File 'plugins/ruberri/search.rb', line 94

def find_methods drv, name
  found = drv.load_methods_matching name
  return nil if found.empty?
  filtered = drv.filter_methods found, name
  methods = []
  filtered.each do |store, mthds|
    mthds.each{|m| methods << [m, store]}
  end
  methods.empty? ? nil : methods
end

- (Object) prepare_class_list(classes)



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'plugins/ruberri/search.rb', line 48

def prepare_class_list classes
  found = {:type => :class}
  list = []
  classes.each do |cls, store|
    data = {
      :store => store.path,
      :friendly_store => store.friendly_path,
      :store_type => store.type,
      :name => cls.full_name
    }
    list << data
  end
  found[:list] = list
  found
end

- (Object) prepare_method_list(methods)



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'plugins/ruberri/search.rb', line 64

def prepare_method_list methods
  found = {:type => :method}
  list = []
  methods.each do |mth, store|
    data = {
      :store => store.path,
      :friendly_store => store.friendly_path,
      :store_type => store.type,
      :name => mth.full_name
    }
    list << data
  end
  found[:list] = list
  found
end

- (Object) search(text)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'plugins/ruberri/search.rb', line 30

def search text
  drv = RDoc::RI::Driver.new
  classes = find_classes drv, text
  methods = find_methods drv, text
  if classes then content = prepare_class_list classes
  elsif methods then content = prepare_method_list methods
  elsif !(hash = drv.classes).empty?
    regexp = /::#{Regexp.quote text}$/
    list = []
    hash.each_key do |cls|
      list << find_classes(drv, cls) if cls =~ regexp
    end
    content = prepare_class_list list
  else content = {}
  end
  content
end