Class: Jazzy::SourceDeclaration

Inherits:
Object
  • Object
show all
Defined in:
lib/jazzy/source_declaration.rb,
lib/jazzy/source_declaration/type.rb,
lib/jazzy/source_declaration/access_control_level.rb

Direct Known Subclasses

SourceDocument

Defined Under Namespace

Classes: AccessControlLevel, Type

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#abstractObject

Returns the value of attribute abstract.



89
90
91
# File 'lib/jazzy/source_declaration.rb', line 89

def abstract
  @abstract
end

#access_control_levelObject

Returns the value of attribute access_control_level.



97
98
99
# File 'lib/jazzy/source_declaration.rb', line 97

def access_control_level
  @access_control_level
end

#childrenObject

counterpart of parent_in_docs



27
28
29
# File 'lib/jazzy/source_declaration.rb', line 27

def children
  @children
end

#columnObject

Returns the value of attribute column.



82
83
84
# File 'lib/jazzy/source_declaration.rb', line 82

def column
  @column
end

#declarationObject

Returns the value of attribute declaration.



87
88
89
# File 'lib/jazzy/source_declaration.rb', line 87

def declaration
  @declaration
end

#default_impl_abstractObject

Returns the value of attribute default_impl_abstract.



90
91
92
# File 'lib/jazzy/source_declaration.rb', line 90

def default_impl_abstract
  @default_impl_abstract
end

#discussionObject

Returns the value of attribute discussion.



92
93
94
# File 'lib/jazzy/source_declaration.rb', line 92

def discussion
  @discussion
end

#end_lineObject

Returns the value of attribute end_line.



99
100
101
# File 'lib/jazzy/source_declaration.rb', line 99

def end_line
  @end_line
end

#fileObject

Returns the value of attribute file.



80
81
82
# File 'lib/jazzy/source_declaration.rb', line 80

def file
  @file
end

#from_protocol_extensionObject

Returns the value of attribute from_protocol_extension.



91
92
93
# File 'lib/jazzy/source_declaration.rb', line 91

def from_protocol_extension
  @from_protocol_extension
end

#lineObject

Returns the value of attribute line.



81
82
83
# File 'lib/jazzy/source_declaration.rb', line 81

def line
  @line
end

#markObject

Returns the value of attribute mark.



96
97
98
# File 'lib/jazzy/source_declaration.rb', line 96

def mark
  @mark
end

#modulenameObject

Returns the value of attribute modulename.



84
85
86
# File 'lib/jazzy/source_declaration.rb', line 84

def modulename
  @modulename
end

#nameObject

Returns the value of attribute name.



85
86
87
# File 'lib/jazzy/source_declaration.rb', line 85

def name
  @name
end

Returns the value of attribute nav_order.



100
101
102
# File 'lib/jazzy/source_declaration.rb', line 100

def nav_order
  @nav_order
end

#objc_nameObject

Returns the value of attribute objc_name.



86
87
88
# File 'lib/jazzy/source_declaration.rb', line 86

def objc_name
  @objc_name
end

#other_language_declarationObject

Returns the value of attribute other_language_declaration.



88
89
90
# File 'lib/jazzy/source_declaration.rb', line 88

def other_language_declaration
  @other_language_declaration
end

#parametersObject

Returns the value of attribute parameters.



94
95
96
# File 'lib/jazzy/source_declaration.rb', line 94

def parameters
  @parameters
end

#parent_in_codeObject

Element containing this declaration in the code



20
21
22
# File 'lib/jazzy/source_declaration.rb', line 20

def parent_in_code
  @parent_in_code
end

#parent_in_docsObject

Logical parent in the documentation. May differ from parent_in_code because of top-level categories and merged extensions.



24
25
26
# File 'lib/jazzy/source_declaration.rb', line 24

def parent_in_docs
  @parent_in_docs
end

#returnObject

Returns the value of attribute return.



93
94
95
# File 'lib/jazzy/source_declaration.rb', line 93

def return
  @return
end

#start_lineObject

Returns the value of attribute start_line.



98
99
100
# File 'lib/jazzy/source_declaration.rb', line 98

def start_line
  @start_line
end

#typeObject

kind of declaration (e.g. class, variable, function)



7
8
9
# File 'lib/jazzy/source_declaration.rb', line 7

def type
  @type
end

#typenameObject

static type of declared element (e.g. String.Type -> ())



9
10
11
# File 'lib/jazzy/source_declaration.rb', line 9

def typename
  @typename
end

#urlObject

Returns the value of attribute url.



95
96
97
# File 'lib/jazzy/source_declaration.rb', line 95

def url
  @url
end

#url_nameObject

Returns the value of attribute url_name.



101
102
103
# File 'lib/jazzy/source_declaration.rb', line 101

def url_name
  @url_name
end

#usrObject

Returns the value of attribute usr.



83
84
85
# File 'lib/jazzy/source_declaration.rb', line 83

def usr
  @usr
end

Instance Method Details

#abstract_globObject



116
117
118
119
120
121
# File 'lib/jazzy/source_declaration.rb', line 116

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_abstractObject



103
104
105
106
107
# File 'lib/jazzy/source_declaration.rb', line 103

def alternative_abstract
  if file = alternative_abstract_file
    Pathname(file).read
  end
end

#alternative_abstract_fileObject



109
110
111
112
113
114
# File 'lib/jazzy/source_declaration.rb', line 109

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

#display_declarationObject



67
68
69
70
71
72
73
# File 'lib/jazzy/source_declaration.rb', line 67

def display_declaration
  if Config.instance.hide_declarations == 'objc'
    other_language_declaration
  else
    declaration
  end
end

#display_other_language_declarationObject



75
76
77
78
# File 'lib/jazzy/source_declaration.rb', line 75

def display_other_language_declaration
  other_language_declaration unless
    %w[swift objc].include? Config.instance.hide_declarations
end

#fully_qualified_nameObject



48
49
50
# File 'lib/jazzy/source_declaration.rb', line 48

def fully_qualified_name
  namespace_path.map(&:name).join('.')
end

#fully_qualified_name_regexpObject

:name doesn’t include any generic type params. This regexp matches any generic type params in parent names.



54
55
56
57
58
# File 'lib/jazzy/source_declaration.rb', line 54

def fully_qualified_name_regexp
  Regexp.new(namespace_path.map(&:name)
                           .map { |n| Regexp.escape(n) }
                           .join('(?:<.*?>)?\.'))
end

#namespace_ancestorsObject



40
41
42
43
44
45
46
# File 'lib/jazzy/source_declaration.rb', line 40

def namespace_ancestors
  if parent_in_code
    parent_in_code.namespace_path
  else
    []
  end
end

#namespace_pathObject

Chain of parent_in_code from top level to self. (Includes self.)



36
37
38
# File 'lib/jazzy/source_declaration.rb', line 36

def namespace_path
  namespace_ancestors + [self]
end

#objc_category_nameObject

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.



63
64
65
# File 'lib/jazzy/source_declaration.rb', line 63

def objc_category_name
  name.split(/[\(\)]/) if type.objc_category?
end

#render?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/jazzy/source_declaration.rb', line 15

def render?
  type?('document.markdown') || children.count != 0
end

#type?(type_kind) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/jazzy/source_declaration.rb', line 11

def type?(type_kind)
  respond_to?(:type) && type.kind == type_kind
end