Class: Solargraph::ApiMap::Constants
- Inherits:
-
Object
- Object
- Solargraph::ApiMap::Constants
- Defined in:
- lib/solargraph/api_map/constants.rb
Overview
Methods for handling constants.
Instance Method Summary collapse
- #clear ⇒ void
-
#collect(*gates) ⇒ Array<Pin::Base>
Collect a list of all constants defined in the specified gates.
-
#dereference(pin) ⇒ String?
Get a fully qualified namespace from a reference pin.
-
#initialize(store) ⇒ Constants
constructor
A new instance of Constants.
-
#qualify(tag, context_tag = '') ⇒ String?
Determine fully qualified tag for a given tag used inside the definition of another tag (“context”).
-
#resolve(name, *gates) ⇒ String?
Resolve a name to a fully qualified namespace or constant.
Constructor Details
#initialize(store) ⇒ Constants
Returns a new instance of Constants.
9 10 11 |
# File 'lib/solargraph/api_map/constants.rb', line 9 def initialize store @store = store end |
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
75 76 77 |
# File 'lib/solargraph/api_map/constants.rb', line 75 def clear [cached_collect, cached_resolve].each(&:clear) end |
#collect(*gates) ⇒ Array<Pin::Base>
Collect a list of all constants defined in the specified gates.
38 39 40 41 |
# File 'lib/solargraph/api_map/constants.rb', line 38 def collect(*gates) flat = gates.flatten cached_collect[flat] || collect_and_cache(flat) end |
#dereference(pin) ⇒ String?
Get a fully qualified namespace from a reference pin.
30 31 32 |
# File 'lib/solargraph/api_map/constants.rb', line 30 def dereference pin resolve(pin.name, pin.reference_gates) end |
#qualify(tag, context_tag = '') ⇒ String?
Determine fully qualified tag for a given tag used inside the definition of another tag (“context”). This method will start the search in the specified context until it finds a match for the tag.
Does not recurse into qualifying the type parameters, but returns any which were passed in unchanged.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/solargraph/api_map/constants.rb', line 58 def qualify tag, context_tag = '' return tag if ['Boolean', 'self', nil].include?(tag) type = ComplexType.try_parse(tag) return unless type.defined? return tag if type.literal? context_type = ComplexType.try_parse(context_tag) return unless context_type.defined? fqns = qualify_namespace(type.rooted_namespace, context_type.rooted_namespace) return unless fqns fqns + type.substring end |
#resolve(name, *gates) ⇒ String?
Resolve a name to a fully qualified namespace or constant.
18 19 20 21 22 23 24 |
# File 'lib/solargraph/api_map/constants.rb', line 18 def resolve(name, *gates) return store.get_path_pins(name[2..]).first&.path if name.start_with?('::') flat = gates.flatten flat.push '' if flat.empty? cached_resolve[[name, flat]] || resolve_and_cache(name, flat) end |