Sha256: c62eb5bf00db3537fad00e54fefb49a4fb6444e140acc1916f39a752dfe58ee2

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

module Leandocument
  class BlobImage
    attr_accessor :path, :base_path, :repository, :commit, :web_path
    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
    
    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

    def image
      if self.commit
        return find_file ? find_file.data : nil
      end
      f?? open(file_path).read : nil
    end
    
    def f?
      File.exist?(file_path)
    end
    
    def file_path
      "#{self.base_path}/#{self.path}"
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
leandocument-0.1.5 lib/leandocument/blob_image.rb
leandocument-0.1.4 lib/leandocument/blob_image.rb
leandocument-0.1.3 lib/leandocument/blob_image.rb
leandocument-0.1.2 lib/leandocument/blob_image.rb
leandocument-0.1.0 lib/leandocument/blob_image.rb
leandocument-0.0.11 lib/leandocument/blob_image.rb
leandocument-0.0.10 lib/leandocument/blob_image.rb
leandocument-0.0.9 lib/leandocument/blob_image.rb
leandocument-0.0.8 lib/leandocument/blob_image.rb
leandocument-0.0.7 lib/leandocument/blob_image.rb
leandocument-0.0.6 lib/leandocument/blob_image.rb
leandocument-0.0.5 lib/leandocument/blob_image.rb
leandocument-0.0.4 lib/leandocument/blob_image.rb
leandocument-0.0.3 lib/leandocument/blob_image.rb
leandocument-0.0.2 lib/leandocument/blob_image.rb
leandocument-0.0.1 lib/leandocument/blob_image.rb