Class: SleepingKingStudios::Docs::Data::ConstantObject
- Defined in:
- lib/sleeping_king_studios/docs/data/constant_object.rb
Overview
Object representing a Ruby constant.
Each constant has a name and a value. In addition, a constant may have a short description, a full description, and metadata.
Instance Method Summary collapse
-
#as_json ⇒ Hash{String => Object}
Generates a JSON-compatible representation of the constant.
-
#data_path ⇒ String
The path to the data file.
-
#description ⇒ String
The full description of the constant, minus the first clause.
-
#metadata ⇒ Object
Additional metadata tags from the documentation.
-
#name ⇒ String
The full, qualified name of the constant.
-
#parent_path ⇒ String
The path to the defining class or module’s data file.
-
#short_description ⇒ String
A short description of the constant.
-
#slug ⇒ String
The name of the constant in url-safe format.
-
#value ⇒ String
A String representation of the value of the constant.
Methods inherited from Base
Constructor Details
This class inherits a constructor from SleepingKingStudios::Docs::Data::Base
Instance Method Details
#as_json ⇒ Hash{String => Object}
Generates a JSON-compatible representation of the constant.
Returns a Hash with the following keys:
-
‘name’: The full, qualified name of the constant.
-
‘slug’: The name of the constant in url-safe format.
-
‘value’: A String representation of the value of the constant.
-
‘short_description’: A short description of the constant.
Additionally, the returned Hash will conditionally include the following keys, if the constant defines at least one of the corresponding code objects.
-
‘description’: The full description of the constant, minus the first clause.
-
‘metadata’: Additional metadata tags from the documentation.
39 40 41 42 43 44 45 46 47 |
# File 'lib/sleeping_king_studios/docs/data/constant_object.rb', line 39 def as_json JSON_PROPERTIES.reduce(required_json) do |memo, property_name| value = send(property_name) next memo if empty?(value) memo.update(property_name.to_s => value) end end |
#data_path ⇒ String
The path to the data file.
52 53 54 |
# File 'lib/sleeping_king_studios/docs/data/constant_object.rb', line 52 def data_path @data_path ||= name.split('::').map { |str| slugify(str) }.join('/') end |
#description ⇒ String
The full description of the constant, minus the first clause.
The remainder of the constant description, if any, after subtracting the short description (separated by the first paragraph break).
64 65 66 67 68 69 70 |
# File 'lib/sleeping_king_studios/docs/data/constant_object.rb', line 64 def description return @description if @description @short_description, @description = split_docstring @description end |
#metadata ⇒ Object
Additional metadata tags from the documentation.
75 76 77 |
# File 'lib/sleeping_king_studios/docs/data/constant_object.rb', line 75 def ||= end |
#name ⇒ String
The full, qualified name of the constant.
82 83 84 |
# File 'lib/sleeping_king_studios/docs/data/constant_object.rb', line 82 def name @name ||= native.path end |
#parent_path ⇒ String
The path to the defining class or module’s data file.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/sleeping_king_studios/docs/data/constant_object.rb', line 89 def parent_path return @parent_path if @parent_path return @parent_path = '' if native.parent.root? parent_class = if native.parent.is_a?(YARD::CodeObjects::ClassObject) SleepingKingStudios::Docs::Data::ClassObject else SleepingKingStudios::Docs::Data::ModuleObject end parent_object = parent_class.new(native: native.parent) @parent_path = parent_object.data_path end |
#short_description ⇒ String
A short description of the constant.
The first part of the constant description, separated by the first paragraph break. Typically should fit on a single line of text.
113 114 115 116 117 118 119 |
# File 'lib/sleeping_king_studios/docs/data/constant_object.rb', line 113 def short_description return @short_description if @short_description @short_description, @description = split_docstring @short_description end |
#slug ⇒ String
The name of the constant in url-safe format.
124 125 126 |
# File 'lib/sleeping_king_studios/docs/data/constant_object.rb', line 124 def slug @slug ||= slugify(name.split('::').last) end |
#value ⇒ String
A String representation of the value of the constant.
131 132 133 |
# File 'lib/sleeping_king_studios/docs/data/constant_object.rb', line 131 def value native.value end |