Class: Leandocument::BlobImage

Inherits:
Object
  • Object
show all
Defined in:
lib/leandocument/blob_image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  self.path = options[:path]
  self.base_path = options[:base_path] || Dir.pwd
  self.web_path  = "#{options[:web_path]}/"
  self.repository = options[:repository]
  self.commit     = options[:commit]
end

Instance Attribute Details

#base_pathObject

Returns the value of attribute base_path.



3
4
5
# File 'lib/leandocument/blob_image.rb', line 3

def base_path
  @base_path
end

#commitObject

Returns the value of attribute commit.



3
4
5
# File 'lib/leandocument/blob_image.rb', line 3

def commit
  @commit
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/leandocument/blob_image.rb', line 3

def path
  @path
end

#repositoryObject

Returns the value of attribute repository.



3
4
5
# File 'lib/leandocument/blob_image.rb', line 3

def repository
  @repository
end

#web_pathObject

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

Returns:

  • (Boolean)


33
34
35
# File 'lib/leandocument/blob_image.rb', line 33

def f?
  File.exist?(file_path)
end

#file_pathObject



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

#imageObject



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