Class: RepoData
- Inherits:
-
Object
- Object
- RepoData
- Defined in:
- lib/teuton-get/repo/repo_data.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #database_filename ⇒ Object
- #get_info(test_id) ⇒ Object
-
#initialize(args) ⇒ RepoData
constructor
A new instance of RepoData.
- #refresh ⇒ Object
- #show_testinfo(item) ⇒ Object
Constructor Details
#initialize(args) ⇒ RepoData
Returns a new instance of RepoData.
12 13 14 15 16 17 |
# File 'lib/teuton-get/repo/repo_data.rb', line 12 def initialize(args) @reader = args[:config_reader] @data = @reader.read @dev = args[:progress_writer] @cache_dirpath = args[:cache_dirpath] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/teuton-get/repo/repo_data.rb', line 10 def data @data end |
Class Method Details
.default ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/teuton-get/repo/repo_data.rb', line 19 def self.default config_filepath = Settings.get(:config_filepath) RepoData.new( config_reader: IniFileReader.new(config_filepath), progress_writer: TerminalWriter.new, cache_dirpath: Settings.get(:cache_dirpath) ) end |
Instance Method Details
#database_filename ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/teuton-get/repo/repo_data.rb', line 61 def database_filename # REVISE: Used by teutonget search... replace by #get() unless Dir.exist? @cache_dirpath puts " [WARN] Create Teuton config files!" puts " Usage: teutonget init" exit 1 end File.join(@cache_dirpath, "database.yaml") end |
#get_info(test_id) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/teuton-get/repo/repo_data.rb', line 40 def get_info(test_id) reponame, id = test_id.split(Settings::SEPARATOR) database = YamlReader.new.read(database_filename) return {} if database[reponame].nil? database[reponame][id] || {} end |
#refresh ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/teuton-get/repo/repo_data.rb', line 28 def refresh @database = {} dirpath = @cache_dirpath FileUtils.rm_r(dirpath) if Dir.exist? dirpath @dev.writeln "\n==> Refreshing active repos" @data.keys.sort.each do |key| refresh_repo key end save_database end |
#show_testinfo(item) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/teuton-get/repo/repo_data.rb', line 47 def show_testinfo(item) return unless item ["name", "author", "date", "desc"].each do |key| @dev.write "#{key.ljust(7)} : ", color: :white @dev.writeln item[key].to_s end ["tags", "files"].each do |key| next if item[key].nil? @dev.write "#{key.ljust(7)} : ", color: :white @dev.writeln item[key].join(", ") end end |