Class: YARD::CodeObjects::ExtraFileObject

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/code_objects/extra_file_object.rb

Overview

An ExtraFileObject represents an extra documentation file (README or other file). It is not strictly a CodeObject (does not inherit from `Base`) although it implements `path`, `name` and `type`, and therefore should be structurally compatible with most CodeObject interfaces.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, contents = nil) ⇒ ExtraFileObject

Creates a new extra file object.

Parameters:

  • filename (String)

    the location on disk of the file

  • contents (String) (defaults to: nil)

    the file contents. If not set, the contents will be read from disk using the filename.



18
19
20
21
22
23
24
25
26
# File 'lib/yard/code_objects/extra_file_object.rb', line 18

def initialize(filename, contents = nil)
  self.filename = filename
  self.name = File.basename(filename).gsub(/\.[^.]+$/, '')
  self.attributes = SymbolHash.new(false)
  @original_contents = contents
  @parsed = false
  @locale = nil
  ensure_parsed
end

Instance Attribute Details

#attributesObject



30
31
32
33
# File 'lib/yard/code_objects/extra_file_object.rb', line 30

def attributes
  ensure_parsed
  @attributes
end

#filenameObject

Returns the value of attribute filename



8
9
10
# File 'lib/yard/code_objects/extra_file_object.rb', line 8

def filename
  @filename
end

#localeObject

Since:

  • 0.8.3



12
13
14
# File 'lib/yard/code_objects/extra_file_object.rb', line 12

def locale
  @locale
end

#nameObject Also known as: path

Returns the value of attribute name



10
11
12
# File 'lib/yard/code_objects/extra_file_object.rb', line 10

def name
  @name
end

Instance Method Details

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



64
65
66
67
# File 'lib/yard/code_objects/extra_file_object.rb', line 64

def ==(other)
  return false unless self.class === other
  other.filename == filename
end

#contentsObject



39
40
41
42
# File 'lib/yard/code_objects/extra_file_object.rb', line 39

def contents
  ensure_parsed
  @contents
end

#contents=(contents) ⇒ Object



44
45
46
47
# File 'lib/yard/code_objects/extra_file_object.rb', line 44

def contents=(contents)
  @original_contents = contents
  @parsed = false
end

#hashObject



70
# File 'lib/yard/code_objects/extra_file_object.rb', line 70

def hash; filename.hash end

#inspectObject Also known as: to_s



57
58
59
# File 'lib/yard/code_objects/extra_file_object.rb', line 57

def inspect
  "#<yardoc #{type} #{filename} attrs=#{attributes.inspect}>"
end

#titleObject



35
36
37
# File 'lib/yard/code_objects/extra_file_object.rb', line 35

def title
  attributes[:title] || name
end

#typeObject



62
# File 'lib/yard/code_objects/extra_file_object.rb', line 62

def type; :extra_file end