Class: YARD::Aggredator::ReferenceableDirective

Inherits:
Tags::Directive
  • Object
show all
Defined in:
lib/yard/aggredator/plugin.rb

Overview

Базовый класс для директив в которых реализована круштая возможность ссылок вроде @!embed (see .schema_id)

Direct Known Subclasses

EmbedDirective, IncludeDirective

Defined Under Namespace

Classes: RefTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, **kwargs, &block) ⇒ ReferenceableDirective

Returns a new instance of ReferenceableDirective.



213
214
215
216
217
# File 'lib/yard/aggredator/plugin.rb', line 213

def initialize(*args, **kwargs, &block)
  super
  @uuid = "#{self.class}_#{rand(1_000_000)}"
  @reference = nil
end

Instance Attribute Details

#referenceObject (readonly)

Returns the value of attribute reference.



211
212
213
# File 'lib/yard/aggredator/plugin.rb', line 211

def reference
  @reference
end

#uuidObject (readonly)

Returns the value of attribute uuid.



211
212
213
# File 'lib/yard/aggredator/plugin.rb', line 211

def uuid
  @uuid
end

Instance Method Details

#callObject



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/yard/aggredator/plugin.rb', line 256

def call
  parser.tags << RefTag.new(self)

  # Директивы регистрируются как 'with_types', поэтому их содержимое может быть в разных местах - в text или types :(
  see = if tag.text.to_s.strip.start_with?('(see')
          tag.text.to_s.strip
        else
          "(#{tag.types&.first.to_s.strip})"
        end

  if reference?
    tuple = detect_reference(see, parser.object)
    @reference = tuple.first
    # Реднерим UUID вида IncludeDirective_<rand> чтоб  в дальнейшем его заменить на контент
    # объект @reference на который есть ссылки пока НЕ существует, его не распарсили.
    self.expanded_text = uuid
  else
    self.expanded_text = expand
  end
end

#detect_reference(content, object) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/yard/aggredator/plugin.rb', line 227

def detect_reference(content, object)
  if content =~ /\A\s*\(see (\S+)\s*\)(?:\s|$)/
    path = ::Regexp.last_match(1)
    extra = ::Regexp.last_match.post_match
    proxy = begin
      CodeObjects::Proxy.new(object, path)
    rescue StandardError
      CodeObjects::Proxy.new(object.parent, path)
    end
    [proxy, extra]
  else
    [nil, content]
  end
end

#directives_from_referenceObject



247
248
249
250
251
252
253
254
# File 'lib/yard/aggredator/plugin.rb', line 247

def directives_from_reference
  return unless reference?

  reference.tags.select do |t|
    # ищем директивы которые срвпадают по типу и по имени если оно было задано в ссылке
    t.tag_name == REFERENCED_TAG_NAME && t.directive.is_a?(self.class) && (name.empty? || name == t.name)
  end.map(&:directive)
end

#nameObject



219
220
221
222
223
224
225
# File 'lib/yard/aggredator/plugin.rb', line 219

def name
  if tag.types&.first.to_s.strip.start_with?('see')
    ''
  else
    tag.types&.first.to_s.strip
  end
end

#reference?Boolean

Returns:

  • (Boolean)


242
243
244
245
# File 'lib/yard/aggredator/plugin.rb', line 242

def reference?
  # Директивы регистрируются как 'with_types', поэтому их содержимое может быть в разных местах - в text или types :(
  @reference || tag.text.to_s.strip.start_with?('(see') || tag.types&.first.to_s.strip.start_with?('see')
end