Class: RiManager

Inherits:
Object
  • Object
show all
Defined in:
lib/RiManager.rb

Overview

This basically is a stripped down version of RiDriver. I cannot use RiDriver directly, because I need to set the driver.

Instance Method Summary collapse

Constructor Details

#initialize(display, path = RI::Paths::PATH) ⇒ RiManager

Returns a new instance of RiManager.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/RiManager.rb', line 37

def initialize(display, path = RI::Paths::PATH)
  # See if search_paths exists, if so, append it to path
  begin 
    path << $cfg.search_paths.split(';')
  rescue
  end
  @reader = RI::RiReader.new(RI::RiCache.new(path))
  @display = display
  @display.reader = @reader
  # prepare all names
  @all_names = prepare_all_names
end

Instance Method Details

#all_namesObject

Returns all fully names as name descriptors



75
76
77
# File 'lib/RiManager.rb', line 75

def all_names
  @all_names
end

#check_namesObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/RiManager.rb', line 62

def check_names
  @reader.all_names.each do |name|
    begin
      if (NameDescriptor.new(name).to_s != name)
        p [name, NameDescriptor.new(name).to_s, NameDescriptor.new(name)]
      end
    rescue RiError => e
      puts e
    end
  end
end

#prepare_all_namesObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/RiManager.rb', line 50

def prepare_all_names
  names = Array.new
  @reader.all_names.each do |name|
    begin
      names.push NameDescriptor.new(name)
    rescue RiError => e
      # silently ignore errors
    end
  end
  names
end

#report_class_stuff(namespace) ⇒ Object

Raises:

  • (RiError)


105
106
107
108
# File 'lib/RiManager.rb', line 105

def report_class_stuff(namespace)
  raise RiError.new("namespace") unless namespace.size==1
  @display.display_class_info @reader.get_class(namespace[0])
end

#report_method_stuff(requested_method_name, methods) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/RiManager.rb', line 110

def report_method_stuff(requested_method_name, methods)
  if methods.size == 1
    method = @reader.get_method(methods[0])
    @display.display_method_info(method)
  else
    entries = methods.find_all {|m| m.name == requested_method_name}
    if entries.size == 1
      method = @reader.get_method(entries[0])
      @display.display_method_info(method)
    else
      puts methods.map {|m| m.full_name}.join(", ")
    end
  end
=begin

  method = if (methods.size == 1)
    @reader.get_method(methods[0])
  else
    entries = methods.find_all {|m| m.name == requested_method_name}
    entries.size
    # there really should be just *one* method that matches.
    raise RiError.new("got a strange method") unless entries.size == 1
    @reader.get_method(entries[0])
  end
  @display.display_method_info(method)
=end
end

#show(name_descriptor, width) ⇒ Object

Searches for the description of a name and shows it using display.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/RiManager.rb', line 80

def show(name_descriptor, width)
  @display.width = width
  # narrow down namespace
  namespace = @reader.top_level_namespace
  name_descriptor.class_names.each do |classname|
    namespace = @reader.lookup_namespace_in(classname, namespace)
    if namespace.empty?
      raise RiError.new("Nothing known about #{name_descriptor}")
    end
  end

  # At this point, if we have multiple possible namespaces, but one
  # is an exact match for our requested class, prune down to just it
  # PS: this comment is shamlessly stolen from ri_driver.rb
  entries = namespace.find_all {|m| m.full_name == name_descriptor.full_class_name}
  namespace = entries if entries.size == 1

  if name_descriptor.method_name
    methods = @reader.find_methods(name_descriptor.method_name, name_descriptor.is_class_method, namespace)
    report_method_stuff(name_descriptor.method_name, methods)
  else
    report_class_stuff(namespace)
  end
end