Class: Gollum::Git::Blob

Inherits:
Object
  • Object
show all
Defined in:
lib/rugged_adapter/git_layer_rugged.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blob, options = {}) ⇒ Blob

Returns a new instance of Blob.



61
62
63
64
65
66
67
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 61

def initialize(blob, options = {})
  @blob = blob
  @mode = options[:mode]
  @name = options[:name]
  @size = options[:size]
  @id = blob.oid
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



54
55
56
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 54

def id
  @id
end

#modeObject (readonly)

Returns the value of attribute mode.



52
53
54
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 52

def mode
  @mode
end

#nameObject (readonly)

Returns the value of attribute name.



53
54
55
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 53

def name
  @name
end

Class Method Details

.create(repo, options) ⇒ Object



56
57
58
59
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 56

def self.create(repo, options)
  blob = repo.git.lookup(options[:id])
  self.new(blob, options)
end

Instance Method Details

#dataObject



69
70
71
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 69

def data
  @content ||= @blob.content
end


73
74
75
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 73

def is_symlink
  @mode == 0120000
end

#mime_typeObject



77
78
79
80
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 77

def mime_type
  guesses = MIME::Types.type_for(self.name) rescue []
  guesses.first ? guesses.first.simplified : DEFAULT_MIME_TYPE
end

#sizeObject



82
83
84
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 82

def size
  @size || @blob.size
end


86
87
88
89
90
91
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 86

def symlink_target(base_path = nil)
  target = data
  new_path = ::File.expand_path(::File.join('..', target), base_path)
  return new_path if ::File.file? new_path
  nil
end