Class: Jazzy::SourceDeclaration
- Inherits:
-
Object
- Object
- Jazzy::SourceDeclaration
- Defined in:
- lib/jazzy/source_declaration.rb,
lib/jazzy/source_declaration/type.rb,
lib/jazzy/source_declaration/access_control_level.rb
Direct Known Subclasses
Defined Under Namespace
Classes: AccessControlLevel, Type
Instance Attribute Summary collapse
-
#abstract ⇒ Object
Returns the value of attribute abstract.
-
#access_control_level ⇒ Object
Returns the value of attribute access_control_level.
-
#children ⇒ Object
counterpart of parent_in_docs.
-
#column ⇒ Object
Returns the value of attribute column.
-
#declaration ⇒ Object
Returns the value of attribute declaration.
-
#default_impl_abstract ⇒ Object
Returns the value of attribute default_impl_abstract.
-
#deprecated ⇒ Object
Returns the value of attribute deprecated.
-
#deprecation_message ⇒ Object
Returns the value of attribute deprecation_message.
-
#discussion ⇒ Object
Returns the value of attribute discussion.
-
#end_line ⇒ Object
Returns the value of attribute end_line.
-
#file ⇒ Object
Returns the value of attribute file.
-
#from_protocol_extension ⇒ Object
Returns the value of attribute from_protocol_extension.
-
#generic_requirements ⇒ Object
Returns the value of attribute generic_requirements.
-
#inherited_types ⇒ Object
Returns the value of attribute inherited_types.
-
#line ⇒ Object
Returns the value of attribute line.
-
#mark ⇒ Object
Returns the value of attribute mark.
-
#modulename ⇒ Object
Returns the value of attribute modulename.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nav_order ⇒ Object
Returns the value of attribute nav_order.
-
#objc_name ⇒ Object
Returns the value of attribute objc_name.
-
#other_language_declaration ⇒ Object
Returns the value of attribute other_language_declaration.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#parent_in_code ⇒ Object
Element containing this declaration in the code.
-
#parent_in_docs ⇒ Object
Logical parent in the documentation.
-
#return ⇒ Object
Returns the value of attribute return.
-
#start_line ⇒ Object
Returns the value of attribute start_line.
-
#type ⇒ Object
kind of declaration (e.g. class, variable, function).
-
#typename ⇒ Object
static type of declared element (e.g. String.Type -> ()).
-
#unavailable ⇒ Object
Returns the value of attribute unavailable.
-
#unavailable_message ⇒ Object
Returns the value of attribute unavailable_message.
-
#url ⇒ Object
Returns the value of attribute url.
-
#url_name ⇒ Object
Returns the value of attribute url_name.
-
#usr ⇒ Object
Returns the value of attribute usr.
Instance Method Summary collapse
- #abstract_glob ⇒ Object
- #alternative_abstract ⇒ Object
- #alternative_abstract_file ⇒ Object
- #constrained_extension? ⇒ Boolean
- #display_declaration ⇒ Object
-
#display_language ⇒ Object
The language in the templates for display.
- #display_other_language_declaration ⇒ Object
- #filepath ⇒ Object
- #fully_qualified_name ⇒ Object
-
#fully_qualified_name_regexp ⇒ Object
:name doesn’t include any generic type params.
- #highlight_language ⇒ Object
- #inherited_types? ⇒ Boolean
- #mark_for_children ⇒ Object
- #namespace_ancestors ⇒ Object
-
#namespace_path ⇒ Object
Chain of parent_in_code from top level to self.
-
#objc_category_name ⇒ Object
If this declaration is an objc category, returns an array with the name of the extended objc class and the category name itself, i.e.
-
#omit_content_from_parent? ⇒ Boolean
When referencing this item from its parent category, include the content or just link to it directly?.
-
#other_inherited_types?(unwanted) ⇒ Boolean
Is there at least one inherited type that is not in the given list?.
-
#render_as_page? ⇒ Boolean
Give the item its own page or just inline into parent?.
- #swift? ⇒ Boolean
- #swift_extension_objc_name ⇒ Object
- #swift_objc_extension? ⇒ Boolean
-
#type_from_doc_module? ⇒ Boolean
SourceKit only sets modulename for imported modules.
- #usage_discouraged? ⇒ Boolean
Instance Attribute Details
#abstract ⇒ Object
Returns the value of attribute abstract.
116 117 118 |
# File 'lib/jazzy/source_declaration.rb', line 116 def abstract @abstract end |
#access_control_level ⇒ Object
Returns the value of attribute access_control_level.
124 125 126 |
# File 'lib/jazzy/source_declaration.rb', line 124 def access_control_level @access_control_level end |
#children ⇒ Object
counterpart of parent_in_docs
39 40 41 |
# File 'lib/jazzy/source_declaration.rb', line 39 def children @children end |
#column ⇒ Object
Returns the value of attribute column.
109 110 111 |
# File 'lib/jazzy/source_declaration.rb', line 109 def column @column end |
#declaration ⇒ Object
Returns the value of attribute declaration.
114 115 116 |
# File 'lib/jazzy/source_declaration.rb', line 114 def declaration @declaration end |
#default_impl_abstract ⇒ Object
Returns the value of attribute default_impl_abstract.
117 118 119 |
# File 'lib/jazzy/source_declaration.rb', line 117 def default_impl_abstract @default_impl_abstract end |
#deprecated ⇒ Object
Returns the value of attribute deprecated.
129 130 131 |
# File 'lib/jazzy/source_declaration.rb', line 129 def deprecated @deprecated end |
#deprecation_message ⇒ Object
Returns the value of attribute deprecation_message.
130 131 132 |
# File 'lib/jazzy/source_declaration.rb', line 130 def @deprecation_message end |
#discussion ⇒ Object
Returns the value of attribute discussion.
119 120 121 |
# File 'lib/jazzy/source_declaration.rb', line 119 def discussion @discussion end |
#end_line ⇒ Object
Returns the value of attribute end_line.
126 127 128 |
# File 'lib/jazzy/source_declaration.rb', line 126 def end_line @end_line end |
#file ⇒ Object
Returns the value of attribute file.
107 108 109 |
# File 'lib/jazzy/source_declaration.rb', line 107 def file @file end |
#from_protocol_extension ⇒ Object
Returns the value of attribute from_protocol_extension.
118 119 120 |
# File 'lib/jazzy/source_declaration.rb', line 118 def from_protocol_extension @from_protocol_extension end |
#generic_requirements ⇒ Object
Returns the value of attribute generic_requirements.
133 134 135 |
# File 'lib/jazzy/source_declaration.rb', line 133 def generic_requirements @generic_requirements end |
#inherited_types ⇒ Object
Returns the value of attribute inherited_types.
134 135 136 |
# File 'lib/jazzy/source_declaration.rb', line 134 def inherited_types @inherited_types end |
#line ⇒ Object
Returns the value of attribute line.
108 109 110 |
# File 'lib/jazzy/source_declaration.rb', line 108 def line @line end |
#mark ⇒ Object
Returns the value of attribute mark.
123 124 125 |
# File 'lib/jazzy/source_declaration.rb', line 123 def mark @mark end |
#modulename ⇒ Object
Returns the value of attribute modulename.
111 112 113 |
# File 'lib/jazzy/source_declaration.rb', line 111 def modulename @modulename end |
#name ⇒ Object
Returns the value of attribute name.
112 113 114 |
# File 'lib/jazzy/source_declaration.rb', line 112 def name @name end |
#nav_order ⇒ Object
Returns the value of attribute nav_order.
127 128 129 |
# File 'lib/jazzy/source_declaration.rb', line 127 def nav_order @nav_order end |
#objc_name ⇒ Object
Returns the value of attribute objc_name.
113 114 115 |
# File 'lib/jazzy/source_declaration.rb', line 113 def objc_name @objc_name end |
#other_language_declaration ⇒ Object
Returns the value of attribute other_language_declaration.
115 116 117 |
# File 'lib/jazzy/source_declaration.rb', line 115 def other_language_declaration @other_language_declaration end |
#parameters ⇒ Object
Returns the value of attribute parameters.
121 122 123 |
# File 'lib/jazzy/source_declaration.rb', line 121 def parameters @parameters end |
#parent_in_code ⇒ Object
Element containing this declaration in the code
32 33 34 |
# File 'lib/jazzy/source_declaration.rb', line 32 def parent_in_code @parent_in_code end |
#parent_in_docs ⇒ Object
Logical parent in the documentation. May differ from parent_in_code because of top-level categories and merged extensions.
36 37 38 |
# File 'lib/jazzy/source_declaration.rb', line 36 def parent_in_docs @parent_in_docs end |
#return ⇒ Object
Returns the value of attribute return.
120 121 122 |
# File 'lib/jazzy/source_declaration.rb', line 120 def return @return end |
#start_line ⇒ Object
Returns the value of attribute start_line.
125 126 127 |
# File 'lib/jazzy/source_declaration.rb', line 125 def start_line @start_line end |
#type ⇒ Object
kind of declaration (e.g. class, variable, function)
8 9 10 |
# File 'lib/jazzy/source_declaration.rb', line 8 def type @type end |
#typename ⇒ Object
static type of declared element (e.g. String.Type -> ())
10 11 12 |
# File 'lib/jazzy/source_declaration.rb', line 10 def typename @typename end |
#unavailable ⇒ Object
Returns the value of attribute unavailable.
131 132 133 |
# File 'lib/jazzy/source_declaration.rb', line 131 def unavailable @unavailable end |
#unavailable_message ⇒ Object
Returns the value of attribute unavailable_message.
132 133 134 |
# File 'lib/jazzy/source_declaration.rb', line 132 def @unavailable_message end |
#url ⇒ Object
Returns the value of attribute url.
122 123 124 |
# File 'lib/jazzy/source_declaration.rb', line 122 def url @url end |
#url_name ⇒ Object
Returns the value of attribute url_name.
128 129 130 |
# File 'lib/jazzy/source_declaration.rb', line 128 def url_name @url_name end |
#usr ⇒ Object
Returns the value of attribute usr.
110 111 112 |
# File 'lib/jazzy/source_declaration.rb', line 110 def usr @usr end |
Instance Method Details
#abstract_glob ⇒ Object
187 188 189 190 191 192 |
# File 'lib/jazzy/source_declaration.rb', line 187 def abstract_glob return [] unless Config.instance.abstract_glob_configured && Config.instance.abstract_glob Config.instance.abstract_glob.select { |e| File.file? e } end |
#alternative_abstract ⇒ Object
174 175 176 177 178 |
# File 'lib/jazzy/source_declaration.rb', line 174 def alternative_abstract if file = alternative_abstract_file Pathname(file).read end end |
#alternative_abstract_file ⇒ Object
180 181 182 183 184 185 |
# File 'lib/jazzy/source_declaration.rb', line 180 def alternative_abstract_file abstract_glob.select do |f| # allow Structs.md or Structures.md [name, url_name].include?(File.basename(f).split('.').first) end.first end |
#constrained_extension? ⇒ Boolean
144 145 146 147 |
# File 'lib/jazzy/source_declaration.rb', line 144 def constrained_extension? type.swift_extension? && generic_requirements end |
#display_declaration ⇒ Object
96 97 98 99 100 |
# File 'lib/jazzy/source_declaration.rb', line 96 def display_declaration return declaration if swift? Config.instance.hide_objc? ? other_language_declaration : declaration end |
#display_language ⇒ Object
The language in the templates for display
90 91 92 93 94 |
# File 'lib/jazzy/source_declaration.rb', line 90 def display_language return 'Swift' if swift? Config.instance.hide_objc? ? 'Swift' : 'Objective-C' end |
#display_other_language_declaration ⇒ Object
102 103 104 105 |
# File 'lib/jazzy/source_declaration.rb', line 102 def display_other_language_declaration other_language_declaration unless Config.instance.hide_objc? || Config.instance.hide_swift? end |
#filepath ⇒ Object
140 141 142 |
# File 'lib/jazzy/source_declaration.rb', line 140 def filepath CGI.unescape(url) end |
#fully_qualified_name ⇒ Object
60 61 62 |
# File 'lib/jazzy/source_declaration.rb', line 60 def fully_qualified_name namespace_path.map(&:name).join('.') end |
#fully_qualified_name_regexp ⇒ Object
:name doesn’t include any generic type params. This regexp matches any generic type params in parent names.
66 67 68 69 70 |
# File 'lib/jazzy/source_declaration.rb', line 66 def fully_qualified_name_regexp Regexp.new(namespace_path.map(&:name) .map { |n| Regexp.escape(n) } .join('(?:<.*?>)?\.')) end |
#highlight_language ⇒ Object
21 22 23 |
# File 'lib/jazzy/source_declaration.rb', line 21 def highlight_language swift? ? Highlighter::SWIFT : Highlighter::OBJC end |
#inherited_types? ⇒ Boolean
157 158 159 160 |
# File 'lib/jazzy/source_declaration.rb', line 157 def inherited_types? inherited_types && !inherited_types.empty? end |
#mark_for_children ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/jazzy/source_declaration.rb', line 149 def mark_for_children if constrained_extension? SourceMark.new_generic_requirements(generic_requirements) else SourceMark.new end end |
#namespace_ancestors ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/jazzy/source_declaration.rb', line 52 def namespace_ancestors if parent_in_code parent_in_code.namespace_path else [] end end |
#namespace_path ⇒ Object
Chain of parent_in_code from top level to self. (Includes self.)
48 49 50 |
# File 'lib/jazzy/source_declaration.rb', line 48 def namespace_path namespace_ancestors + [self] end |
#objc_category_name ⇒ Object
If this declaration is an objc category, returns an array with the name of the extended objc class and the category name itself, i.e. [“NSString”, “MyMethods”], nil otherwise.
75 76 77 |
# File 'lib/jazzy/source_declaration.rb', line 75 def objc_category_name name.split(/[\(\)]/) if type.objc_category? end |
#omit_content_from_parent? ⇒ Boolean
When referencing this item from its parent category, include the content or just link to it directly?
27 28 29 |
# File 'lib/jazzy/source_declaration.rb', line 27 def omit_content_from_parent? false end |
#other_inherited_types?(unwanted) ⇒ Boolean
Is there at least one inherited type that is not in the given list?
163 164 165 166 |
# File 'lib/jazzy/source_declaration.rb', line 163 def other_inherited_types?(unwanted) return false unless inherited_types? inherited_types.any? { |t| !unwanted.include?(t) } end |
#render_as_page? ⇒ Boolean
Give the item its own page or just inline into parent?
13 14 15 |
# File 'lib/jazzy/source_declaration.rb', line 13 def render_as_page? children.any? end |
#swift? ⇒ Boolean
17 18 19 |
# File 'lib/jazzy/source_declaration.rb', line 17 def swift? type.swift_type? end |
#swift_extension_objc_name ⇒ Object
83 84 85 86 87 |
# File 'lib/jazzy/source_declaration.rb', line 83 def swift_extension_objc_name return unless type.swift_extension? && usr usr.split('(cs)').last end |
#swift_objc_extension? ⇒ Boolean
79 80 81 |
# File 'lib/jazzy/source_declaration.rb', line 79 def swift_objc_extension? type.swift_extension? && usr && usr.start_with?('c:objc') end |
#type_from_doc_module? ⇒ Boolean
SourceKit only sets modulename for imported modules
169 170 171 172 |
# File 'lib/jazzy/source_declaration.rb', line 169 def type_from_doc_module? !type.extension? || (swift? && usr && modulename.nil?) end |
#usage_discouraged? ⇒ Boolean
136 137 138 |
# File 'lib/jazzy/source_declaration.rb', line 136 def usage_discouraged? unavailable || deprecated end |