Class: YARD::Server::LibraryVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/server/library_version.rb

Overview

Since:

  • 0.6.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version = nil, yardoc = nil, source = :disk) ⇒ LibraryVersion

Returns a new instance of LibraryVersion.

Since:

  • 0.6.0



14
15
16
17
18
19
20
# File 'lib/yard/server/library_version.rb', line 14

def initialize(name, version = nil, yardoc = nil, source = :disk)
  self.name = name
  self.yardoc_file = yardoc
  self.version = version
  self.source = source
  self.source_path = load_source_path
end

Instance Attribute Details

#nameObject

Since:

  • 0.6.0



8
9
10
# File 'lib/yard/server/library_version.rb', line 8

def name
  @name
end

#sourceObject

Since:

  • 0.6.0



11
12
13
# File 'lib/yard/server/library_version.rb', line 11

def source
  @source
end

#source_pathObject

Since:

  • 0.6.0



12
13
14
# File 'lib/yard/server/library_version.rb', line 12

def source_path
  @source_path
end

#versionObject

Since:

  • 0.6.0



9
10
11
# File 'lib/yard/server/library_version.rb', line 9

def version
  @version
end

#yardoc_fileObject

Since:

  • 0.6.0



10
11
12
# File 'lib/yard/server/library_version.rb', line 10

def yardoc_file
  @yardoc_file
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==, equal?

Returns:

  • (Boolean)

Since:

  • 0.6.0



28
29
30
31
# File 'lib/yard/server/library_version.rb', line 28

def eql?(other)
  other.is_a?(LibraryVersion) && other.name == name && 
    other.version == version && other.yardoc_file == yardoc_file
end

#gemspecObject

Since:

  • 0.6.0



41
42
43
44
# File 'lib/yard/server/library_version.rb', line 41

def gemspec
  ver = version ? "= #{version}" : ">= 0"
  Gem.source_index.find_name(name, ver).first
end

#hashObject

Since:

  • 0.6.0



26
# File 'lib/yard/server/library_version.rb', line 26

def hash; to_s.hash end

#load_yardoc_from_diskObject (protected)

Since:

  • 0.6.0



48
49
50
# File 'lib/yard/server/library_version.rb', line 48

def load_yardoc_from_disk
  nil
end

#load_yardoc_from_gemObject (protected)

Since:

  • 0.6.0



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/yard/server/library_version.rb', line 52

def load_yardoc_from_gem
  require 'rubygems'
  ver = version ? "= #{version}" : ">= 0"
  self.yardoc_file = Registry.yardoc_file_for_gem(name, ver)
  unless yardoc_file && File.directory?(yardoc_file)
    Thread.new do
      # Build gem docs on demand
      log.debug "Building gem docs for #{to_s(false)}"
      CLI::Gems.run(name, ver)
      self.yardoc_file = Registry.yardoc_file_for_gem(name, ver)
      FileUtils.touch(File.join(yardoc_file, 'complete'))
    end
  end
  unless yardoc_file && File.exist?(File.join(yardoc_file, 'complete'))
    raise LibraryNotPreparedError
  end
end

#prepare!Object

Since:

  • 0.6.0



35
36
37
38
39
# File 'lib/yard/server/library_version.rb', line 35

def prepare!
  return if yardoc_file
  meth = "load_yardoc_from_#{source}"
  send(meth) if respond_to?(meth)
end

#source_path_for_diskObject (protected)

Since:

  • 0.6.0



70
71
72
# File 'lib/yard/server/library_version.rb', line 70

def source_path_for_disk
  File.dirname(yardoc_file) if yardoc_file
end

#source_path_for_gemObject (protected)

Since:

  • 0.6.0



74
75
76
# File 'lib/yard/server/library_version.rb', line 74

def source_path_for_gem
  gemspec.full_gem_path if gemspec
end

#to_s(url_format = true) ⇒ Object

Since:

  • 0.6.0



22
23
24
# File 'lib/yard/server/library_version.rb', line 22

def to_s(url_format = true)
  version ? "#{name}#{url_format ? '/' : '-'}#{version}" : "#{name}"
end