Class: RepoData

Inherits:
Object
  • Object
show all
Defined in:
lib/teuton-get/repo/repo_data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ RepoData

Returns a new instance of RepoData.



10
11
12
13
14
15
# File 'lib/teuton-get/repo/repo_data.rb', line 10

def initialize(args)
  @reader = args[:config_reader]
  @data = @reader.read
  @dev = args[:progress_writer]
  @cache_dirpath = args[:cache_dirpath]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/teuton-get/repo/repo_data.rb', line 8

def data
  @data
end

Class Method Details

.new_by_defaultObject



17
18
19
20
21
22
23
24
# File 'lib/teuton-get/repo/repo_data.rb', line 17

def self.new_by_default
  config_filepath = Application.instance.get(:config_filepath)
  RepoData.new(
    config_reader: IniFileReader.new(config_filepath),
    progress_writer: TerminalWriter.new,
    cache_dirpath: Application.instance.get(:cache_dirpath)
  )
end

Instance Method Details

#database_filenameObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/teuton-get/repo/repo_data.rb', line 59

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(test_id) ⇒ Object



38
39
40
41
42
43
# File 'lib/teuton-get/repo/repo_data.rb', line 38

def get(test_id)
  reponame, id = test_id.split(Application::SEPARATOR)
  database = YamlReader.new.read(database_filename)
  return {} if database[reponame].nil?
  database[reponame][id]
end

#refreshObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/teuton-get/repo/repo_data.rb', line 26

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



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/teuton-get/repo/repo_data.rb', line 45

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