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.
Instance Method Summary collapse
-
#attr_listing(object) ⇒ Array<YARD::CodeObjects::MethodObject>
Returns the visible attribute methods for an object.
-
#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:`.
-
#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.
-
#sort_listing(list) ⇒ Array<YARD::CodeObjects::Base>
Sorts a listing by scope and case-insensitive name.
Instance Method Details
#attr_listing(object) ⇒ Array<YARD::CodeObjects::MethodObject>
Returns the visible attribute methods for an object.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/yard/markdown/object_listing_helper.rb', line 46 def attr_listing(object) attrs = [] object.inheritance_tree(true).each do |superclass| next if !..empty? && !.(superclass) %i[class instance].each do |scope| superclass.attributes.fetch(scope).each do |_name, rw| attr = prune_method_listing([rw.fetch(:read), rw.fetch(:write)].compact, false).first attrs << attr if attr end end break if ..empty? end sort_listing(attrs) end |
#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 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:`.
82 83 84 |
# File 'lib/yard/markdown/object_listing_helper.rb', line 82 def hidden_object?(object) object.docstring.lstrip.start_with?(':nodoc:') 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| hidden_object?(item) } .sort_by { |method_object| method_object.name } end |
#sort_listing(list) ⇒ Array<YARD::CodeObjects::Base>
Sorts a listing by scope and case-insensitive name.
69 70 71 72 73 74 75 76 |
# File 'lib/yard/markdown/object_listing_helper.rb', line 69 def sort_listing(list) list.sort do |left, right| scope_comparison = left.scope <=> right.scope next scope_comparison unless scope_comparison.zero? left.name.to_s.casecmp(right.name.to_s) end end |