Class: GitLocal::Object
- Inherits:
-
Object
- Object
- GitLocal::Object
- Defined in:
- lib/git_local/object.rb
Defined Under Namespace
Classes: NotFound
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ Object
constructor
A new instance of Object.
- #name ⇒ Object
- #read(max_lines = nil) ⇒ Object
- #sha ⇒ Object
- #size ⇒ Object
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
#path ⇒ Object (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
#name ⇒ Object
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 |
#sha ⇒ Object
24 25 26 |
# File 'lib/git_local/object.rb', line 24 def sha Digest::SHA1.hexdigest("blob " + contents.length.to_s + "\0" + contents) end |
#size ⇒ Object
28 29 30 |
# File 'lib/git_local/object.rb', line 28 def size File.size(path).to_f / 2**20 end |