Class: Gitrob::Models::Blob

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/gitrob/models/blob.rb

Constant Summary collapse

SHA_REGEX =
/[a-f0-9]{40}/
TEST_BLOB_INDICATORS =
%w(test spec fixture mock stub fake demo sample)
LARGE_BLOB_THRESHOLD =
102_400

Instance Method Summary collapse

Instance Method Details

#extensionObject



26
27
28
# File 'lib/gitrob/models/blob.rb', line 26

def extension
  File.extname(path)[1..-1]
end

#filenameObject



22
23
24
# File 'lib/gitrob/models/blob.rb', line 22

def filename
  File.basename(path)
end

#history_html_urlObject



41
42
43
# File 'lib/gitrob/models/blob.rb', line 41

def history_html_url
  "#{repository.html_url}/commits/#{repository.default_branch}/#{path}"
end

#html_urlObject



37
38
39
# File 'lib/gitrob/models/blob.rb', line 37

def html_url
  "#{repository.html_url}/blob/#{repository.default_branch}/#{path}"
end

#large?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/gitrob/models/blob.rb', line 45

def large?
  size.to_i > LARGE_BLOB_THRESHOLD
end

#test_blob?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/gitrob/models/blob.rb', line 30

def test_blob?
  TEST_BLOB_INDICATORS.each do |indicator|
    return true if path.downcase.include?(indicator)
  end
  false
end

#validateObject



16
17
18
19
20
# File 'lib/gitrob/models/blob.rb', line 16

def validate
  super
  validates_presence [:path, :size, :sha]
  validates_format SHA_REGEX, :sha
end