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.



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

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



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

def attributes
  ensure_parsed
  @attributes
end

#filenameObject

Returns the value of attribute filename



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

def filename
  @filename
end

#localeObject

Since:

  • 0.8.3



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

def locale
  @locale
end

#nameObject Also known as: path

Returns the value of attribute name



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

def name
  @name
end

Instance Method Details

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



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

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

#contentsObject



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

def contents
  ensure_parsed
  @contents
end

#contents=(contents) ⇒ Object



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

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

#hashObject



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

def hash; filename.hash end

#inspectObject Also known as: to_s



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

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

#titleObject



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

def title
  attributes[:title] || name
end

#typeObject



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

def type; :extra_file end