Class: Skap::Files::Versions

Inherits:
YAMLFile show all
Defined in:
lib/skap/files/versions.rb

Overview

Class for file “versions.yaml” (this file describes versions of works in project repository).

Instance Method Summary collapse

Methods inherited from YAMLFile

#initialize

Constructor Details

This class inherits a constructor from Skap::YAMLFile

Instance Method Details

#add_document(document_path, document) ⇒ void

This method returns an undefined value.

Parameters:

  • document_path (String)
  • document (Hash<String, Object>)


10
11
12
13
14
15
# File 'lib/skap/files/versions.rb', line 10

def add_document(document_path, document)
  file[document_path] = document
  @file = file.sort_by(&:first).to_h

  update_file
end

#covered_sourcesSet<String>

Returns:

  • (Set<String>)


18
19
20
21
22
23
24
# File 'lib/skap/files/versions.rb', line 18

def covered_sources
  result = Set.new

  file.each_value { |value| result.merge(value["sources"].keys) }

  result
end

#find_document(document_path) ⇒ Hash<String, Object>

Parameters:

  • document_path (String)

Returns:

  • (Hash<String, Object>)


28
29
30
# File 'lib/skap/files/versions.rb', line 28

def find_document(document_path)
  file[document_path]
end

#outdated_documentsArray<Array(String, Array<String>)>

Returns:

  • (Array<Array(String, Array<String>)>)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/skap/files/versions.rb', line 33

def outdated_documents
  sources_sha = {}

  file.filter_map do |doc_path, hash|
    outdated_sources =
      hash["sources"].filter_map do |source_path, source_data|
        sha = (sources_sha[source_path] ||= yield(source_path))
        source_path if !sha.nil? && sha != source_data["sha"]
      end
    [doc_path, outdated_sources] if !outdated_sources.empty?
  end
end