Class: Inch::Codebase::Objects

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/inch/codebase/objects.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objects) ⇒ Objects

Returns a new instance of Objects.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/inch/codebase/objects.rb', line 17

def initialize(objects)
  list = objects.map do |o|
    proxy = CodeObject::Proxy.for(o)
    proxy.object_lookup = self
    proxy
  end
  @list = list
  index_by_fullname
  # the @list has to be set for the priority sorting
  # since the priority needs the object_lookup, which
  # in turn depends on @list - it's a crazy world
  @list = self.class.sort_by_priority(@list)
end

Class Method Details

.sort_by_priority(objects) ⇒ Array<CodeObject::Proxy::Base>

Parameters:

Returns:



11
12
13
14
15
# File 'lib/inch/codebase/objects.rb', line 11

def self.sort_by_priority(objects)
  objects.sort_by do |o|
    [o.priority, o.score, o.fullname.size]
  end.reverse
end

Instance Method Details

#allArray<CodeObject::Proxy::Base>

Returns all parsed objects as code object proxies



35
36
37
# File 'lib/inch/codebase/objects.rb', line 35

def all
  @list
end

#filter!(options) ⇒ void

This method returns an undefined value.

Filters the list based on the settings in options



69
70
71
72
# File 'lib/inch/codebase/objects.rb', line 69

def filter!(options)
  @list = ObjectsFilter.new(all, options).objects
  index_by_fullname
end

#find(fullname) ⇒ CodeObject::Proxy::Base

Returns the object with the given fullname

Examples:


find("Foo#bar")
# => returns the code object proxy for Foo#bar

Parameters:

  • fullname (String)

    partial fullname/name of an object

Returns:



48
49
50
# File 'lib/inch/codebase/objects.rb', line 48

def find(fullname)
  @by_fullname[fullname]
end

#starting_with(partial_name) ⇒ Array<CodeObject::Proxy::Base>

Returns all objects where the fullname starts_with the given partial_name

Examples:


find("Foo#")
# => returns the code object proxies for all instance methods of Foo

Parameters:

  • partial_name (String)

    partial name of an object

Returns:



62
63
64
# File 'lib/inch/codebase/objects.rb', line 62

def starting_with(partial_name)
  all.select { |o| o.fullname.start_with?(partial_name) }
end