Class: Gollum::File

Inherits:
Object
  • Object
show all
Defined in:
lib/gollum/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wiki) ⇒ File

Public: Initialize a file.

wiki - The Gollum::Wiki in question.

Returns a newly initialized Gollum::File.



10
11
12
13
14
# File 'lib/gollum/file.rb', line 10

def initialize(wiki)
  @wiki = wiki
  @blob = nil
  @path = nil
end

Instance Attribute Details

#pathObject (readonly)

Public: The String path of the file.



34
35
36
# File 'lib/gollum/file.rb', line 34

def path
  @path
end

#versionObject (readonly)

Public: The Grit::Commit version of the file.



31
32
33
# File 'lib/gollum/file.rb', line 31

def version
  @version
end

Instance Method Details

#find(name, version) ⇒ Object

Find a file in the given Gollum repo.

name - The full String path. version - The String version ID to find.

Returns a Gollum::File or nil if the file could not be found.



53
54
55
56
57
58
59
60
61
62
# File 'lib/gollum/file.rb', line 53

def find(name, version)
  checked = name.downcase
  map     = @wiki.tree_map_for(version)
  if entry = map.detect { |entry| entry.path.downcase == checked }
    @path    = name
    @blob    = entry.blob(@wiki.repo)
    @version = version.is_a?(Grit::Commit) ? version : @wiki.commit_for(version)
    self
  end
end

#mime_typeObject

Public: The String mime type of the file.



37
38
39
# File 'lib/gollum/file.rb', line 37

def mime_type
  @blob.mime_type
end

#nameObject

Public: The on-disk filename of the file.

Returns the String name.



19
20
21
# File 'lib/gollum/file.rb', line 19

def name
  @blob && @blob.name
end

#raw_dataObject

Public: The raw contents of the page.

Returns the String data.



26
27
28
# File 'lib/gollum/file.rb', line 26

def raw_data
  @blob && @blob.data
end