Class: Gemnasium::DependencyFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/gemnasium/dependency_files.rb

Constant Summary collapse

SUPPORTED_DEPENDENCY_FILES =
/(Gemfile|Gemfile\.lock|.*\.gemspec|package\.json|npm-shrinkwrap\.json|setup\.py|requirements\.txt|requires\.txt|composer\.json|composer\.lock)$/

Class Method Summary collapse

Class Method Details

.get_content_to_upload(project_path, files_path) ⇒ Array

Get the content to upload to Gemnasium.

Parameters:

  • files_path (Array)

    an array containing the path of the files

Returns:

  • (Array)

    array of hashes containing file name, file sha and file content



24
25
26
27
28
# File 'lib/gemnasium/dependency_files.rb', line 24

def self.get_content_to_upload(project_path, files_path)
  files_path.inject([]) do |arr, file_path|
    arr << { filename: file_path, sha: calculate_sha1(file_path), content: File.open("#{project_path}/#{file_path}") {|io| io.read} }
  end
end

.get_sha1s_hash(project_path) ⇒ Hash

Get a Hash of sha1s for each file corresponding to the regex

Parameters:

  • regexp (Regexp)

    the regular expression of requested files

Returns:

  • (Hash)

    the hash associating each file path with its SHA1 hash



12
13
14
15
16
17
18
# File 'lib/gemnasium/dependency_files.rb', line 12

def self.get_sha1s_hash(project_path)
  Dir.chdir(project_path)
  Dir.glob("**/**").grep(SUPPORTED_DEPENDENCY_FILES).inject({}) do |h, file_path|
    h[file_path] = calculate_sha1("#{project_path}/#{file_path}") unless is_ignored?(file_path)
    h
  end
end