Class: Gitmain::Blob

Inherits:
Object
  • Object
show all
Defined in:
lib/gitmain/blob.rb

Direct Known Subclasses

TextBlob

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, id, path = nil, name = nil) ⇒ Blob

Returns a new instance of Blob.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
# File 'lib/gitmain/blob.rb', line 5

def initialize(repository, id, path = nil, name = nil)
  raise ArgumentError, 'provide a valid repository' unless repository.kind_of?(Gitmain::Repository)
  raise ArgumentError, 'provide a valid blob id' unless id.to_s.match(/\A[0-9a-f]{40}\z/)
  @repository = repository
  @id = id
  @path = path
  @name = name
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/gitmain/blob.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/gitmain/blob.rb', line 3

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/gitmain/blob.rb', line 3

def path
  @path
end

#repositoryObject (readonly)

Returns the value of attribute repository.



3
4
5
# File 'lib/gitmain/blob.rb', line 3

def repository
  @repository
end

Instance Method Details

#changed_attributesObject



14
15
16
# File 'lib/gitmain/blob.rb', line 14

def changed_attributes
  @changed_attributes ||= {}
end

#contentObject



18
19
20
# File 'lib/gitmain/blob.rb', line 18

def content
  @content ||= _blob&.content
end

#content=(value) ⇒ Object



22
23
24
25
# File 'lib/gitmain/blob.rb', line 22

def content=(value)
  changed_attributes[:content] = content
  @content = value
end

#file_nameObject



27
28
29
# File 'lib/gitmain/blob.rb', line 27

def file_name
  File.join(*[path, name].map(&:to_s).reject(&:empty?))
end