Class: GitLocal::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/git_local/object.rb

Defined Under Namespace

Classes: NotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Object

Returns a new instance of Object.



8
9
10
# File 'lib/git_local/object.rb', line 8

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/git_local/object.rb', line 3

def path
  @path
end

Instance Method Details

#nameObject



12
13
14
# File 'lib/git_local/object.rb', line 12

def name
  path.rindex("/") ? path[path.rindex("/") + 1..-1] : path
end

#read(max_lines = nil) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/git_local/object.rb', line 16

def read(max_lines = nil)
  return contents if max_lines.nil?

  File.foreach(path).first(max_lines).join
rescue StandardError => e
  raise NotFound
end

#shaObject



24
25
26
# File 'lib/git_local/object.rb', line 24

def sha
  Digest::SHA1.hexdigest("blob " + contents.length.to_s + "\0" + contents)
end

#sizeObject



28
29
30
# File 'lib/git_local/object.rb', line 28

def size
  File.size(path).to_f / 2**20
end