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(language, objects) ⇒ Objects

Returns a new instance of Objects


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

def initialize(language, objects)
  list = objects.map do |code_object|
    Codebase::Object.new(language, code_object, self)
  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>

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>

Returns all parsed objects as code object proxies

Returns:

See Also:


33
34
35
# File 'lib/inch/codebase/objects.rb', line 33

def all
  @list
end

#filter!(options) ⇒ void

This method returns an undefined value.

Filters the list based on the settings in options


67
68
69
70
# File 'lib/inch/codebase/objects.rb', line 67

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

#find(fullname) ⇒ CodeObject::Proxy

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:


46
47
48
# File 'lib/inch/codebase/objects.rb', line 46

def find(fullname)
  @by_fullname[fullname]
end

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

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:


60
61
62
# File 'lib/inch/codebase/objects.rb', line 60

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