Module: Yard::Yaml::Tags

Defined in:
lib/yard/yaml/tags.rb

Class Method Summary collapse

Class Method Details

.register!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/yard/yaml/tags.rb', line 13

def register!
  return unless defined?(::YARD) && ::YARD.const_defined?(:Tags)

  # Ensure a minimal Library exists under ::YARD::Tags if missing
  unless ::YARD::Tags.const_defined?(:Library, false)
    # If the test provided a top-level ::Library constant, attach it.
    if defined?(::Library) && ::Library.is_a?(Module)
      begin
        ::YARD::Tags.const_set(:Library, ::Library)
      rescue StandardError
        return
      end
    else
      # Create a minimal shim that records define_tag calls
      lib = Module.new
      class << lib
        attr_accessor :calls
        def define_tag(*args)
          self.calls ||= []
          self.calls << args
        end
      end
      begin
        ::YARD::Tags.const_set(:Library, lib)
      rescue StandardError
        # if we failed to set, just return silently
        return
      end
    end
  end

  begin
    ::YARD::Tags::Library.define_tag("YAML", :yaml, :with_title_and_text)
  rescue StandardError
    # ignore if already defined or unavailable
  end
  begin
    ::YARD::Tags::Library.define_tag("YAML File", :yaml_file, :with_text)
  rescue StandardError
    # ignore if already defined or unavailable
  end
end