Module: YARD::Markdown::ObjectListingHelper

Defined in:
lib/yard/markdown/object_listing_helper.rb

Overview

Collects and sorts the objects shown on a rendered object page.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.constant_listing(object) ⇒ Array<YARD::CodeObjects::Base>

Returns the constants and class variables defined on an object.

Parameters:

  • object (YARD::CodeObjects::NamespaceObject)

    Object being rendered.

Returns:

  • (Array<YARD::CodeObjects::Base>)

    Constants and class variables.



11
12
13
14
# File 'lib/yard/markdown/object_listing_helper.rb', line 11

def self.constant_listing(object)
  constants = object.constants(included: false, inherited: false)
  constants + object.cvars
end

.hidden_object?(object) ⇒ Boolean

Returns whether an object is explicitly hidden with :nodoc:.

Parameters:

  • object (YARD::CodeObjects::Base)

    Listed object whose docstring may start with :nodoc:.

Returns:

  • (Boolean)

    True when the object should be hidden.



64
65
66
# File 'lib/yard/markdown/object_listing_helper.rb', line 64

def self.hidden_object?(object)
  object.docstring.start_with?(":nodoc:")
end

.sort_attributes(attributes) ⇒ Array<YARD::CodeObjects::MethodObject>

Sorts attributes by scope and case-insensitive name.

Parameters:

  • attributes (Array<YARD::CodeObjects::MethodObject>)

    Attribute methods collected from eligible ancestors.

Returns:

  • (Array<YARD::CodeObjects::MethodObject>)

    Sorted attributes.



56
57
58
# File 'lib/yard/markdown/object_listing_helper.rb', line 56

def self.sort_attributes(attributes)
  attributes.sort { |left, right| (left.scope <=> right.scope).nonzero? || left.name.to_s.casecmp(right.name.to_s) }
end

Instance Method Details

#attr_listing(object) ⇒ Array<YARD::CodeObjects::MethodObject>

Returns the visible attribute methods for an object.

Parameters:

  • object (YARD::CodeObjects::NamespaceObject)

    Object being rendered.

Returns:

  • (Array<YARD::CodeObjects::MethodObject>)

    Sorted attribute methods.



46
47
48
49
50
# File 'lib/yard/markdown/object_listing_helper.rb', line 46

def attr_listing(object)
  superclasses = attribute_superclasses(object)
  attributes = superclasses.flat_map { |superclass| attributes_for(superclass) }
  ObjectListingHelper.sort_attributes(attributes)
end

#public_class_methods(object) ⇒ Array<YARD::CodeObjects::MethodObject>

Returns the public class methods defined directly on an object.

Parameters:

  • object (YARD::CodeObjects::NamespaceObject)

    Object being rendered.

Returns:

  • (Array<YARD::CodeObjects::MethodObject>)

    Sorted public class methods.



30
31
32
# File 'lib/yard/markdown/object_listing_helper.rb', line 30

def public_class_methods(object)
  public_method_list(object).select { |item| item.scope == :class }
end

#public_instance_methods(object) ⇒ Array<YARD::CodeObjects::MethodObject>

Returns the public instance methods defined directly on an object.

Parameters:

  • object (YARD::CodeObjects::NamespaceObject)

    Object being rendered.

Returns:

  • (Array<YARD::CodeObjects::MethodObject>)

    Sorted public instance methods.



38
39
40
# File 'lib/yard/markdown/object_listing_helper.rb', line 38

def public_instance_methods(object)
  public_method_list(object).select { |item| item.scope == :instance }
end

#public_method_list(object) ⇒ Array<YARD::CodeObjects::MethodObject>

Returns the visible public methods defined directly on an object.

Parameters:

  • object (YARD::CodeObjects::NamespaceObject)

    Object being rendered.

Returns:

  • (Array<YARD::CodeObjects::MethodObject>)

    Sorted public methods.



20
21
22
23
24
# File 'lib/yard/markdown/object_listing_helper.rb', line 20

def public_method_list(object)
  prune_method_listing(object.meths(inherited: false, visibility: :public))
    .reject { |item| ObjectListingHelper.hidden_object?(item) }
    .sort_by { |method_object| method_object.name }
end