Class: RDocF95::RI::ClassEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc-f95/ri/cache.rb

Direct Known Subclasses

TopLevelEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_name, name, in_class) ⇒ ClassEntry

Returns a new instance of ClassEntry.



8
9
10
11
12
13
14
15
# File 'lib/rdoc-f95/ri/cache.rb', line 8

def initialize(path_name, name, in_class)
  @path_names = [ path_name ]
  @name = name
  @in_class = in_class
  @class_methods    = []
  @instance_methods = []
  @inferior_classes = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rdoc-f95/ri/cache.rb', line 5

def name
  @name
end

#path_namesObject (readonly)

Returns the value of attribute path_names.



6
7
8
# File 'lib/rdoc-f95/ri/cache.rb', line 6

def path_names
  @path_names
end

Instance Method Details

#add_path(path) ⇒ Object

We found this class in more tha one place, so add in the name from there.



19
20
21
# File 'lib/rdoc-f95/ri/cache.rb', line 19

def add_path(path)
  @path_names << path
end

#all_method_namesObject

Return a list of all out method names



102
103
104
105
106
# File 'lib/rdoc-f95/ri/cache.rb', line 102

def all_method_names
  res = @class_methods.map {|m| m.full_name }
  @instance_methods.each {|m| res << m.full_name}
  res
end

#classes_and_modulesObject



67
68
69
# File 'lib/rdoc-f95/ri/cache.rb', line 67

def classes_and_modules
  @inferior_classes
end

#contained_class_named(name) ⇒ Object

Return an exact match to a particular name



72
73
74
# File 'lib/rdoc-f95/ri/cache.rb', line 72

def contained_class_named(name)
  @inferior_classes.find {|c| c.name == name}
end

#contained_modules_matching(name) ⇒ Object

Return a list of any classes or modules that we contain that match a given string



63
64
65
# File 'lib/rdoc-f95/ri/cache.rb', line 63

def contained_modules_matching(name)
  @inferior_classes.find_all {|c| c.name[name]}
end

#full_nameObject

Return our full name



95
96
97
98
99
# File 'lib/rdoc-f95/ri/cache.rb', line 95

def full_name
  res = @in_class.full_name
  res << "::" unless res.empty?
  res << @name
end

#load_from(dir) ⇒ Object

read in our methods and any classes and modules in our namespace. Methods are stored in files called name-c|i.yaml, where the ‘name’ portion is the external form of the method name and the c|i is a class|instance flag



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rdoc-f95/ri/cache.rb', line 30

def load_from(dir)
  Dir.foreach(dir) do |name|
    next if name =~ /^\./

    # convert from external to internal form, and
    # extract the instance/class flag

    if name =~ /^(.*?)-(c|i).yaml$/
      external_name = $1
      is_class_method = $2 == "c"
      internal_name = RiWriter.external_to_internal(external_name)
      list = is_class_method ? @class_methods : @instance_methods
      path = File.join(dir, name)
      list << MethodEntry.new(path, internal_name, is_class_method, self)
    else
      full_name = File.join(dir, name)
      if File.directory?(full_name)
        inf_class = @inferior_classes.find {|c| c.name == name }
        if inf_class
          inf_class.add_path(full_name)
        else
          inf_class = ClassEntry.new(full_name, name, self)
          @inferior_classes << inf_class
        end
        inf_class.load_from(full_name)
      end
    end
  end
end

#methods_matching(name, is_class_method) ⇒ Object

return the list of local methods matching name We’re split into two because we need distinct behavior when called from the toplevel



79
80
81
# File 'lib/rdoc-f95/ri/cache.rb', line 79

def methods_matching(name, is_class_method)
  local_methods_matching(name, is_class_method)
end

#recursively_find_methods_matching(name, is_class_method) ⇒ Object

Find methods matching ‘name’ in ourselves and in any classes we contain



85
86
87
88
89
90
91
# File 'lib/rdoc-f95/ri/cache.rb', line 85

def recursively_find_methods_matching(name, is_class_method)
  res = local_methods_matching(name, is_class_method)
  @inferior_classes.each do |c|
    res.concat(c.recursively_find_methods_matching(name, is_class_method))
  end
  res
end