Class: SleepingKingStudios::Docs::RegistryQuery
- Inherits:
-
Object
- Object
- SleepingKingStudios::Docs::RegistryQuery
- Defined in:
- lib/sleeping_king_studios/docs/registry_query.rb
Overview
Checks for the presence of requested data in the YARD registry.
Instance Method Summary collapse
-
#class_method_exists?(method_name) ⇒ Boolean
Checks if the given class method is defined in the registry.
-
#constant_exists?(constant_name) ⇒ Boolean
Checks if the given constant is defined in the registry.
-
#definition_exists?(module_name) ⇒ Boolean
Checks if the given class or module is defined in the registry.
-
#initialize(registry:) ⇒ RegistryQuery
constructor
A new instance of RegistryQuery.
-
#instance_method_exists?(method_name) ⇒ Boolean
Checks if the given instance method is defined in the registry.
Constructor Details
#initialize(registry:) ⇒ RegistryQuery
Returns a new instance of RegistryQuery.
9 10 11 |
# File 'lib/sleeping_king_studios/docs/registry_query.rb', line 9 def initialize(registry:) @registry = registry end |
Instance Method Details
#class_method_exists?(method_name) ⇒ Boolean
Checks if the given class method is defined in the registry.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sleeping_king_studios/docs/registry_query.rb', line 19 def class_method_exists?(method_name) # Handle top-level class methods. if method_name.start_with?('.') return top_level_class_method_exists?(method_name) end # Handle legacy ::class_method format. unless method_name.include?('.') return legacy_class_method_exists?(method_name) end registry.any? do |obj| obj.type == :method && obj.scope == :class && obj.title == method_name end end |
#constant_exists?(constant_name) ⇒ Boolean
Checks if the given constant is defined in the registry.
41 42 43 44 45 |
# File 'lib/sleeping_king_studios/docs/registry_query.rb', line 41 def constant_exists?(constant_name) registry.any? do |obj| obj.type == :constant && obj.title == constant_name end end |
#definition_exists?(module_name) ⇒ Boolean
Checks if the given class or module is defined in the registry.
53 54 55 56 57 |
# File 'lib/sleeping_king_studios/docs/registry_query.rb', line 53 def definition_exists?(module_name) registry.any? do |obj| (obj.type == :module || obj.type == :class) && obj.title == module_name # rubocop:disable Style/MultipleComparison end end |
#instance_method_exists?(method_name) ⇒ Boolean
Checks if the given instance method is defined in the registry.
65 66 67 68 69 70 71 |
# File 'lib/sleeping_king_studios/docs/registry_query.rb', line 65 def instance_method_exists?(method_name) registry.any? do |obj| obj.type == :method && obj.scope == :instance && obj.title == method_name end end |