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.



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

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.



67
68
69
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 67

def id
  @id
end

#modeObject (readonly)

Returns the value of attribute mode.



65
66
67
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 65

def mode
  @mode
end

#nameObject (readonly)

Returns the value of attribute name.



66
67
68
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 66

def name
  @name
end

Class Method Details

.create(repo, options) ⇒ Object



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

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

Instance Method Details

#dataObject



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

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


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

def is_symlink
  @mode == 0120000
end

#mime_typeObject



90
91
92
93
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 90

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

#sizeObject



95
96
97
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 95

def size
  @size || @blob.size
end


99
100
101
102
103
104
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 99

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