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

- (ExtraFileObject) initialize(filename, contents = nil)

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.



16
17
18
19
20
21
# File 'lib/yard/code_objects/extra_file_object.rb', line 16

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

Instance Attribute Details

- (Object) attributes

Returns the value of attribute attributes



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

def attributes
  @attributes
end

- (Object) contents

Returns the value of attribute contents



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

def contents
  @contents
end

- (Object) filename

Returns the value of attribute filename



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

def filename
  @filename
end

- (Object) name 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

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



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

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

- (Object) hash



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

def hash; filename.hash end

- (Object) inspect Also known as: to_s



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

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

- (Object) title



25
26
27
# File 'lib/yard/code_objects/extra_file_object.rb', line 25

def title
  attributes[:title] || name
end

- (Object) type



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

def type; 'extra_file' end