Class: Skap::Files::Sources

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

Overview

Class for file “sources.yaml” (this file describes sources 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_source(dir) ⇒ void

This method returns an undefined value.

Parameters:

  • dir (String)


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

def add_source(dir)
  file[dir] = {"file-extensions" => [], "ignored" => [], "indexed" => []}
  @file = file.sort_by(&:first).to_h

  update_file
end

#delete_source(dir) ⇒ void

This method returns an undefined value.

Parameters:

  • dir (String)


18
19
20
21
# File 'lib/skap/files/sources.rb', line 18

def delete_source(dir)
  file.delete(dir)
  update_file
end

#extract(key, dirs = []) ⇒ Hash<String, Array<String>>

Parameters:

  • key (String)
  • dirs (Array<String>) (defaults to: [])

Returns:

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


26
27
28
29
30
31
# File 'lib/skap/files/sources.rb', line 26

def extract(key, dirs = [])
  sources = dirs.empty? ? file : file.slice(*dirs)
  sources
    .transform_values { |v| v[key] }
    .reject { |_, v| v.nil? || v.empty? }
end

#select_directories!(dirs) ⇒ Hash<String, Hash<String, Array<String>>>

Parameters:

  • dirs (Array<String>)

Returns:

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


35
36
37
# File 'lib/skap/files/sources.rb', line 35

def select_directories!(dirs)
  @file = file.slice(*dirs)
end