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
-
.constant_listing(object) ⇒ Array<YARD::CodeObjects::Base>
Returns the constants and class variables defined on an object.
-
.hidden_object?(object) ⇒ Boolean
Returns whether an object is explicitly hidden with
:nodoc:. -
.sort_attributes(attributes) ⇒ Array<YARD::CodeObjects::MethodObject>
Sorts attributes by scope and case-insensitive name.
Instance Method Summary collapse
-
#attr_listing(object) ⇒ Array<YARD::CodeObjects::MethodObject>
Returns the visible attribute methods for an object.
-
#public_class_methods(object) ⇒ Array<YARD::CodeObjects::MethodObject>
Returns the public class methods defined directly on an object.
-
#public_instance_methods(object) ⇒ Array<YARD::CodeObjects::MethodObject>
Returns the public instance methods defined directly on an object.
-
#public_method_list(object) ⇒ Array<YARD::CodeObjects::MethodObject>
Returns the visible public methods defined directly on an object.
Class Method Details
.constant_listing(object) ⇒ Array<YARD::CodeObjects::Base>
Returns the constants and class variables defined on an object.
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:.
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.
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.
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.
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.
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.
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 |