Class: RepoMgr::Config
- Inherits:
-
Object
- Object
- RepoMgr::Config
- Defined in:
- lib/repo_mgr/config.rb
Overview
handles repo-mgr configuration
Instance Attribute Summary collapse
-
#cfg ⇒ Object
readonly
Returns the value of attribute cfg.
-
#cfg_dir ⇒ Object
readonly
Returns the value of attribute cfg_dir.
Instance Method Summary collapse
- #add_pkg(repo, path) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #remove_pkg(repo, path) ⇒ Object
- #save ⇒ Object
- #upsert_repo(options) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/repo_mgr/config.rb', line 13 def initialize @cfg_dir = "#{ENV['HOME']}/.repo-mgr" FileUtils.mkdir_p @cfg_dir @cfg_file = "#{@cfg_dir}/repo-mgr.yml" unless File.exist? @cfg_file File.write @cfg_file, { repos: {}, packages: {} }.to_yaml end @cfg = YAML.load_file @cfg_file end |
Instance Attribute Details
#cfg ⇒ Object (readonly)
Returns the value of attribute cfg.
11 12 13 |
# File 'lib/repo_mgr/config.rb', line 11 def cfg @cfg end |
#cfg_dir ⇒ Object (readonly)
Returns the value of attribute cfg_dir.
11 12 13 |
# File 'lib/repo_mgr/config.rb', line 11 def cfg_dir @cfg_dir end |
Instance Method Details
#add_pkg(repo, path) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/repo_mgr/config.rb', line 50 def add_pkg(repo, path) if @cfg[:repos][repo].nil? Tools.error "unable to add packages to #{repo} - repo does not exist" end @cfg[:packages] ||= {} @cfg[:packages][repo] ||= [] pkg = File.basename path if @cfg[:packages][repo].include?(pkg) Tools.error "you already have #{pkg} in your #{repo} repo" end @cfg[:packages][repo] << pkg save end |
#remove_pkg(repo, path) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/repo_mgr/config.rb', line 68 def remove_pkg(repo, path) if @cfg[:repos][repo].nil? Tools.error "unable to remove packages from #{repo} "\ '- repo does not exist' end @cfg[:packages] ||= {} @cfg[:packages][repo] ||= [] pkg = File.basename path @cfg[:packages][repo].delete pkg save end |
#save ⇒ Object
25 26 27 |
# File 'lib/repo_mgr/config.rb', line 25 def save File.write @cfg_file, @cfg.to_yaml end |
#upsert_repo(options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/repo_mgr/config.rb', line 29 def upsert_repo() name = [:name] type = [:type] if @cfg[:repos][name] && @cfg[:repos][name][:type] != type Tools.error "unable to change type for #{name} repository" end @cfg[:repos][name] = { type: type, path: [:path], keyid: [:keyid] } if [:publisher] @cfg[:repos][name][:publisher] = [:publisher] end save end |