Class: Jazzy::SourceDeclaration::Type
- Inherits:
-
Object
- Object
- Jazzy::SourceDeclaration::Type
- Defined in:
- lib/jazzy/source_declaration/type.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- TYPES =
{ # Markdown 'document.markdown' => { jazzy: 'Guide', dash: 'Guide', }.freeze, # Objective-C 'sourcekitten.source.lang.objc.decl.unexposed' => { jazzy: 'Unexposed', dash: 'Unexposed', }.freeze, 'sourcekitten.source.lang.objc.decl.category' => { jazzy: 'Category', dash: 'Extension', }.freeze, 'sourcekitten.source.lang.objc.decl.class' => { jazzy: 'Class', dash: 'Class', }.freeze, 'sourcekitten.source.lang.objc.decl.constant' => { jazzy: 'Constant', dash: 'Constant', }.freeze, 'sourcekitten.source.lang.objc.decl.enum' => { jazzy: 'Enum', dash: 'Enum', }.freeze, 'sourcekitten.source.lang.objc.decl.enumcase' => { jazzy: 'Enum Case', dash: 'Case', }.freeze, 'sourcekitten.source.lang.objc.decl.initializer' => { jazzy: 'Initializer', dash: 'Initializer', }.freeze, 'sourcekitten.source.lang.objc.decl.method.class' => { jazzy: 'Class Method', dash: 'Method', }.freeze, 'sourcekitten.source.lang.objc.decl.method.instance' => { jazzy: 'Instance Method', dash: 'Method', }.freeze, 'sourcekitten.source.lang.objc.decl.property' => { jazzy: 'Property', dash: 'Property', }.freeze, 'sourcekitten.source.lang.objc.decl.protocol' => { jazzy: 'Protocol', dash: 'Protocol', }.freeze, 'sourcekitten.source.lang.objc.decl.typedef' => { jazzy: 'Type Definition', dash: 'Type', }.freeze, 'sourcekitten.source.lang.objc.mark' => { jazzy: 'Mark', dash: 'Mark', }.freeze, 'sourcekitten.source.lang.objc.decl.function' => { jazzy: 'Function', dash: 'Function', }.freeze, 'sourcekitten.source.lang.objc.decl.struct' => { jazzy: 'Struct', dash: 'Struct', }.freeze, 'sourcekitten.source.lang.objc.decl.field' => { jazzy: 'Field', dash: 'Field', }.freeze, 'sourcekitten.source.lang.objc.decl.ivar' => { jazzy: 'Ivar', dash: 'Ivar', }.freeze, 'sourcekitten.source.lang.objc.module.import' => { jazzy: 'Module', dash: 'Module', }.freeze, # Swift 'source.lang.swift.decl.function.accessor.address' => { jazzy: 'Address Accessor', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.didset' => { jazzy: 'DidSet Accessor', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.getter' => { jazzy: 'Getter Accessor', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.mutableaddress' => { jazzy: 'Mutable Address Accessor', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.setter' => { jazzy: 'Setter Accessor', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.willset' => { jazzy: 'WillSet Accessor', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.operator' => { jazzy: 'Operator', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.operator.infix' => { jazzy: 'Infix Operator', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.operator.postfix' => { jazzy: 'Postfix Operator', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.operator.prefix' => { jazzy: 'Prefix Operator', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.method.class' => { jazzy: 'Class Method', dash: 'Method', }.freeze, 'source.lang.swift.decl.var.class' => { jazzy: 'Class Variable', dash: 'Variable', }.freeze, 'source.lang.swift.decl.class' => { jazzy: 'Class', dash: 'Class', }.freeze, 'source.lang.swift.decl.function.constructor' => { jazzy: 'Constructor', dash: 'Constructor', }.freeze, 'source.lang.swift.decl.function.destructor' => { jazzy: 'Destructor', dash: 'Method', }.freeze, 'source.lang.swift.decl.var.global' => { jazzy: 'Global Variable', dash: 'Global', }.freeze, 'source.lang.swift.decl.enumcase' => { jazzy: 'Enum Case', dash: 'Case', }.freeze, 'source.lang.swift.decl.enumelement' => { jazzy: 'Enum Element', dash: 'Element', }.freeze, 'source.lang.swift.decl.enum' => { jazzy: 'Enum', dash: 'Enum', }.freeze, 'source.lang.swift.decl.extension' => { jazzy: 'Extension', dash: 'Extension', }.freeze, 'source.lang.swift.decl.extension.class' => { jazzy: 'Class Extension', dash: 'Extension', }.freeze, 'source.lang.swift.decl.extension.enum' => { jazzy: 'Enum Extension', dash: 'Extension', }.freeze, 'source.lang.swift.decl.extension.protocol' => { jazzy: 'Protocol Extension', dash: 'Extension', }.freeze, 'source.lang.swift.decl.extension.struct' => { jazzy: 'Struct Extension', dash: 'Extension', }.freeze, 'source.lang.swift.decl.function.free' => { jazzy: 'Function', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.method.instance' => { jazzy: 'Instance Method', dash: 'Method', }.freeze, 'source.lang.swift.decl.var.instance' => { jazzy: 'Instance Variable', dash: 'Property', }.freeze, 'source.lang.swift.decl.var.local' => { jazzy: 'Local Variable', dash: 'Variable', }.freeze, 'source.lang.swift.decl.var.parameter' => { jazzy: 'Parameter', dash: 'Parameter', }.freeze, 'source.lang.swift.decl.protocol' => { jazzy: 'Protocol', dash: 'Protocol', }.freeze, 'source.lang.swift.decl.function.method.static' => { jazzy: 'Static Method', dash: 'Method', }.freeze, 'source.lang.swift.decl.var.static' => { jazzy: 'Static Variable', dash: 'Variable', }.freeze, 'source.lang.swift.decl.struct' => { jazzy: 'Struct', dash: 'Struct', }.freeze, 'source.lang.swift.decl.function.subscript' => { jazzy: 'Subscript', dash: 'Method', }.freeze, 'source.lang.swift.decl.typealias' => { jazzy: 'Typealias', dash: 'Alias', }.freeze, 'source.lang.swift.decl.generic_type_param' => { jazzy: 'Generic Type Parameter', dash: 'Parameter', }.freeze, 'source.lang.swift.decl.associatedtype' => { jazzy: 'Associated Type', dash: 'Alias', }.freeze, }.freeze
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #dash_type ⇒ Object
- #declaration? ⇒ Boolean
- #equals ⇒ Object
- #extension? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(kind) ⇒ Type
constructor
A new instance of Type.
- #mark? ⇒ Boolean
- #name ⇒ Object
- #name_controlled_manually? ⇒ Boolean
- #objc_category? ⇒ Boolean
- #objc_class? ⇒ Boolean
- #objc_enum? ⇒ Boolean
- #objc_typedef? ⇒ Boolean
- #objc_unexposed? ⇒ Boolean
- #param? ⇒ Boolean
- #plural_name ⇒ Object
- #should_document? ⇒ Boolean
- #swift_enum_case? ⇒ Boolean
- #swift_enum_element? ⇒ Boolean
- #swift_extensible? ⇒ Boolean
- #swift_extension? ⇒ Boolean
- #swift_protocol? ⇒ Boolean
Constructor Details
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
11 12 13 |
# File 'lib/jazzy/source_declaration/type.rb', line 11 def kind @kind end |
Class Method Details
.all ⇒ Object
7 8 9 |
# File 'lib/jazzy/source_declaration/type.rb', line 7 def self.all TYPES.keys.map { |k| new(k) } end |
Instance Method Details
#==(other) ⇒ Object
111 112 113 |
# File 'lib/jazzy/source_declaration/type.rb', line 111 def ==(other) other && kind == other.kind end |
#dash_type ⇒ Object
18 19 20 |
# File 'lib/jazzy/source_declaration/type.rb', line 18 def dash_type @type && @type[:dash] end |
#declaration? ⇒ Boolean
70 71 72 73 |
# File 'lib/jazzy/source_declaration/type.rb', line 70 def declaration? kind.start_with?('source.lang.swift.decl', 'sourcekitten.source.lang.objc.decl') end |
#equals ⇒ Object
110 |
# File 'lib/jazzy/source_declaration/type.rb', line 110 alias equals == |
#extension? ⇒ Boolean
75 76 77 |
# File 'lib/jazzy/source_declaration/type.rb', line 75 def extension? swift_extension? || objc_category? end |
#hash ⇒ Object
106 107 108 |
# File 'lib/jazzy/source_declaration/type.rb', line 106 def hash kind.hash end |
#mark? ⇒ Boolean
37 38 39 40 |
# File 'lib/jazzy/source_declaration/type.rb', line 37 def mark? kind == 'source.lang.swift.syntaxtype.comment.mark' || kind == 'sourcekitten.source.lang.objc.mark' end |
#name ⇒ Object
22 23 24 |
# File 'lib/jazzy/source_declaration/type.rb', line 22 def name @type && @type[:jazzy] end |
#name_controlled_manually? ⇒ Boolean
26 27 28 29 30 31 |
# File 'lib/jazzy/source_declaration/type.rb', line 26 def name_controlled_manually? !kind.start_with?('source') # "'source'.lang..." for Swift # or "'source'kitten.source..." for Objective-C # but not "Overview" for navigation groups. end |
#objc_category? ⇒ Boolean
50 51 52 |
# File 'lib/jazzy/source_declaration/type.rb', line 50 def objc_category? kind == 'sourcekitten.source.lang.objc.decl.category' end |
#objc_class? ⇒ Boolean
54 55 56 |
# File 'lib/jazzy/source_declaration/type.rb', line 54 def objc_class? kind == 'sourcekitten.source.lang.objc.decl.class' end |
#objc_enum? ⇒ Boolean
42 43 44 |
# File 'lib/jazzy/source_declaration/type.rb', line 42 def objc_enum? kind == 'sourcekitten.source.lang.objc.decl.enum' end |
#objc_typedef? ⇒ Boolean
46 47 48 |
# File 'lib/jazzy/source_declaration/type.rb', line 46 def objc_typedef? kind == 'sourcekitten.source.lang.objc.decl.typedef' end |
#objc_unexposed? ⇒ Boolean
98 99 100 |
# File 'lib/jazzy/source_declaration/type.rb', line 98 def objc_unexposed? kind == 'sourcekitten.source.lang.objc.decl.unexposed' end |
#param? ⇒ Boolean
91 92 93 94 95 96 |
# File 'lib/jazzy/source_declaration/type.rb', line 91 def param? # SourceKit strangely categorizes initializer parameters as local # variables, so both kinds represent a parameter in jazzy. kind == 'source.lang.swift.decl.var.parameter' || kind == 'source.lang.swift.decl.var.local' end |
#plural_name ⇒ Object
33 34 35 |
# File 'lib/jazzy/source_declaration/type.rb', line 33 def plural_name name.pluralize end |
#should_document? ⇒ Boolean
66 67 68 |
# File 'lib/jazzy/source_declaration/type.rb', line 66 def should_document? declaration? && !param? end |
#swift_enum_case? ⇒ Boolean
58 59 60 |
# File 'lib/jazzy/source_declaration/type.rb', line 58 def swift_enum_case? kind == 'source.lang.swift.decl.enumcase' end |
#swift_enum_element? ⇒ Boolean
62 63 64 |
# File 'lib/jazzy/source_declaration/type.rb', line 62 def swift_enum_element? kind == 'source.lang.swift.decl.enumelement' end |
#swift_extensible? ⇒ Boolean
83 84 85 |
# File 'lib/jazzy/source_declaration/type.rb', line 83 def swift_extensible? kind =~ /^source\.lang\.swift\.decl\.(class|struct|protocol|enum)$/ end |
#swift_extension? ⇒ Boolean
79 80 81 |
# File 'lib/jazzy/source_declaration/type.rb', line 79 def swift_extension? kind =~ /^source\.lang\.swift\.decl\.extension.*/ end |
#swift_protocol? ⇒ Boolean
87 88 89 |
# File 'lib/jazzy/source_declaration/type.rb', line 87 def swift_protocol? kind == 'source.lang.swift.decl.protocol' end |