Module: Solargraph::ComplexType::TypeMethods
- Included in:
- UniqueType
- Defined in:
- lib/solargraph/complex_type/type_methods.rb
Overview
Methods for accessing type data.
Instance Attribute Summary collapse
- #name ⇒ String readonly
- #substring ⇒ String readonly
- #subtypes ⇒ Array<ComplexType> readonly
- #tag ⇒ String readonly
Instance Method Summary collapse
- #==(other) ⇒ Object
- #defined? ⇒ Boolean
- #duck_type? ⇒ Boolean
- #fixed_parameters? ⇒ Boolean
- #hash_parameters? ⇒ Boolean
- #key_types ⇒ Array<ComplexType>
- #list_parameters? ⇒ Boolean
- #namespace ⇒ String
- #nil_type? ⇒ Boolean
- #parameters? ⇒ Boolean
-
#qualify(api_map, context = '') ⇒ ComplexType
Generate a ComplexType that fully qualifies this type’s namespaces.
-
#scope ⇒ Symbol
:class or :instance.
- #undefined? ⇒ Boolean
- #value_types ⇒ Array<ComplexType>
- #void? ⇒ Boolean
Instance Attribute Details
#name ⇒ String (readonly)
7 8 9 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 7 def name @name end |
#substring ⇒ String (readonly)
10 11 12 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 10 def substring @substring end |
#subtypes ⇒ Array<ComplexType> (readonly)
16 17 18 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 16 def subtypes @subtypes end |
#tag ⇒ String (readonly)
13 14 15 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 13 def tag @tag end |
Instance Method Details
#==(other) ⇒ Object
83 84 85 86 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 83 def == other return false unless self.class == other.class tag == other.tag end |
#defined? ⇒ Boolean
37 38 39 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 37 def defined? !undefined? end |
#duck_type? ⇒ Boolean
19 20 21 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 19 def duck_type? @duck_type ||= name.start_with?('#') end |
#fixed_parameters? ⇒ Boolean
51 52 53 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 51 def fixed_parameters? substring.start_with?('(') end |
#hash_parameters? ⇒ Boolean
56 57 58 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 56 def hash_parameters? substring.start_with?('{') end |
#key_types ⇒ Array<ComplexType>
66 67 68 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 66 def key_types @key_types end |
#list_parameters? ⇒ Boolean
46 47 48 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 46 def list_parameters? substring.start_with?('<') end |
#namespace ⇒ String
71 72 73 74 75 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 71 def namespace @namespace ||= 'Object' if duck_type? @namespace ||= 'NilClass' if nil_type? @namespace ||= (name == 'Class' || name == 'Module') && !subtypes.empty? ? subtypes.first.name : name end |
#nil_type? ⇒ Boolean
24 25 26 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 24 def nil_type? @nil_type ||= (name.downcase == 'nil') end |
#parameters? ⇒ Boolean
29 30 31 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 29 def parameters? !substring.empty? end |
#qualify(api_map, context = '') ⇒ ComplexType
Generate a ComplexType that fully qualifies this type’s namespaces.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 93 def qualify api_map, context = '' return ComplexType.parse(tag) if duck_type? or void? or undefined? fqns = api_map.qualify(name, context) return ComplexType::UNDEFINED if fqns.nil? ltypes = key_types.map do |t| t.qualify api_map, context end rtypes = value_types.map do |t| t.qualify api_map, context end if list_parameters? Solargraph::ComplexType.parse("#{fqns}<#{rtypes.map(&:tag).join(', ')}>").first elsif fixed_parameters? Solargraph::ComplexType.parse("#{fqns}(#{rtypes.map(&:tag).join(', ')})").first elsif hash_parameters? Solargraph::ComplexType.parse("#{fqns}{#{ltypes.map(&:tag).join(', ')} => #{rtypes.map(&:tag).join(', ')}}").first else Solargraph::ComplexType.parse(fqns).first end end |
#scope ⇒ Symbol
Returns :class or :instance.
78 79 80 81 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 78 def scope @scope ||= :instance if duck_type? || nil_type? @scope ||= (name == 'Class' || name == 'Module') && !subtypes.empty? ? :class : :instance end |
#undefined? ⇒ Boolean
41 42 43 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 41 def undefined? name == 'undefined' end |
#value_types ⇒ Array<ComplexType>
61 62 63 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 61 def value_types @subtypes end |
#void? ⇒ Boolean
33 34 35 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 33 def void? name == 'void' end |