Class: Skap::Files::Sources
- Defined in:
- lib/skap/files/sources.rb
Overview
Class for file “sources.yaml” (this file describes sources in project repository).
Instance Method Summary collapse
- #add_source(dir) ⇒ void
- #delete_source(dir) ⇒ void
- #extract(key, dirs = []) ⇒ Hash<String, Array<String>>
- #select_directories!(dirs) ⇒ Hash<String, Hash<String, Array<String>>>
Methods inherited from YAMLFile
Constructor Details
This class inherits a constructor from Skap::YAMLFile
Instance Method Details
#add_source(dir) ⇒ void
This method returns an undefined value.
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.
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>>
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>>>
35 36 37 |
# File 'lib/skap/files/sources.rb', line 35 def select_directories!(dirs) @file = file.slice(*dirs) end |