Class: Leandocument::BlobImage
- Inherits:
-
Object
- Object
- Leandocument::BlobImage
- Defined in:
- lib/leandocument/blob_image.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#commit ⇒ Object
Returns the value of attribute commit.
-
#path ⇒ Object
Returns the value of attribute path.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#web_path ⇒ Object
Returns the value of attribute web_path.
Instance Method Summary collapse
- #f? ⇒ Boolean
- #file_path ⇒ Object
- #find_file(tree = nil, path = nil) ⇒ Object
- #image ⇒ Object
-
#initialize(options = {}) ⇒ BlobImage
constructor
A new instance of BlobImage.
Constructor Details
#initialize(options = {}) ⇒ BlobImage
Returns a new instance of BlobImage.
4 5 6 7 8 9 10 |
# File 'lib/leandocument/blob_image.rb', line 4 def initialize( = {}) self.path = [:path] self.base_path = [:base_path] || Dir.pwd self.web_path = "#{[:web_path]}/" self.repository = [:repository] self.commit = [:commit] end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
3 4 5 |
# File 'lib/leandocument/blob_image.rb', line 3 def base_path @base_path end |
#commit ⇒ Object
Returns the value of attribute commit.
3 4 5 |
# File 'lib/leandocument/blob_image.rb', line 3 def commit @commit end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/leandocument/blob_image.rb', line 3 def path @path end |
#repository ⇒ Object
Returns the value of attribute repository.
3 4 5 |
# File 'lib/leandocument/blob_image.rb', line 3 def repository @repository end |
#web_path ⇒ Object
Returns the value of attribute web_path.
3 4 5 |
# File 'lib/leandocument/blob_image.rb', line 3 def web_path @web_path end |
Instance Method Details
#f? ⇒ Boolean
33 34 35 |
# File 'lib/leandocument/blob_image.rb', line 33 def f? File.exist?(file_path) end |
#file_path ⇒ Object
37 38 39 |
# File 'lib/leandocument/blob_image.rb', line 37 def file_path "#{self.base_path}/#{self.path}" end |
#find_file(tree = nil, path = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/leandocument/blob_image.rb', line 12 def find_file(tree = nil, path = nil) path = path || self.path paths = path.split("/") file_name = paths.last paths = paths[0..-2] (tree || self.commit.tree).contents.each do |content| if paths.size > 0 return find_file(content, (paths[1..-1].push(file_name)).join("/")) if content.name == paths[0] else return content if content.name == file_name end end end |
#image ⇒ Object
26 27 28 29 30 31 |
# File 'lib/leandocument/blob_image.rb', line 26 def image if self.commit return find_file ? find_file.data : nil end f?? open(file_path).read : nil end |