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.



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

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.



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

def id
  @id
end

#modeObject (readonly)

Returns the value of attribute mode.



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

def mode
  @mode
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.create(repo, options) ⇒ Object



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

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

Instance Method Details

#dataObject



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

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


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

def is_symlink
  @mode == 0120000
end

#mime_typeObject



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

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

#sizeObject



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

def size
  @size || @blob.size
end


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

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