Class: Akabei::Omakase::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/akabei/omakase/config.rb

Defined Under Namespace

Classes: InvalidConfig

Constant Summary collapse

FILE_NAME =
'.akabei.yml'
REQUIRED_ATTRIBUTES =
%w[
  name
  package_key
  repo_key
  srcdest
  logdest
  pkgbuild
].freeze
REQUIRED_BUILD_ATTRIBUTES =
%w[makepkg pacman]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



24
25
26
# File 'lib/akabei/omakase/config.rb', line 24

def initialize
  @config = {}
end

Class Method Details

.loadObject



14
15
16
17
18
# File 'lib/akabei/omakase/config.rb', line 14

def self.load
  config = new
  config.load(FILE_NAME)
  config
end

Instance Method Details

#abs_path(arch) ⇒ Object



108
109
110
# File 'lib/akabei/omakase/config.rb', line 108

def abs_path(arch)
  repo_path(arch).join("#{@config['name']}.abs.tar.gz")
end

#buildsObject



92
93
94
# File 'lib/akabei/omakase/config.rb', line 92

def builds
  @config['builds']
end

#db_path(arch) ⇒ Object



100
101
102
# File 'lib/akabei/omakase/config.rb', line 100

def db_path(arch)
  repo_path(arch).join("#{@config['name']}.db")
end

#files_path(arch) ⇒ Object



104
105
106
# File 'lib/akabei/omakase/config.rb', line 104

def files_path(arch)
  repo_path(arch).join("#{@config['name']}.files")
end

#load(path) ⇒ Object



28
29
30
31
32
33
# File 'lib/akabei/omakase/config.rb', line 28

def load(path)
  @config.merge!(SafeYAML.load_file(path, deserialize_symbols: true))
  true
rescue Errno::ENOENT
  false
end

#logdestObject



72
73
74
# File 'lib/akabei/omakase/config.rb', line 72

def logdest
  Pathname.new(@config['logdest'])
end

#nameObject



64
65
66
# File 'lib/akabei/omakase/config.rb', line 64

def name
  @config['name']
end

#package_dir(package_name) ⇒ Object



80
81
82
# File 'lib/akabei/omakase/config.rb', line 80

def package_dir(package_name)
  pkgbuild.join(package_name)
end

#package_signerObject



84
85
86
# File 'lib/akabei/omakase/config.rb', line 84

def package_signer
  Signer.get(@config['package_key'])
end

#pkgbuildObject



76
77
78
# File 'lib/akabei/omakase/config.rb', line 76

def pkgbuild
  Pathname.new(@config['pkgbuild'])
end

#repo_path(arch) ⇒ Object



96
97
98
# File 'lib/akabei/omakase/config.rb', line 96

def repo_path(arch)
  Pathname.new(@config['name']).join('os', arch)
end

#repo_signerObject



88
89
90
# File 'lib/akabei/omakase/config.rb', line 88

def repo_signer
  Signer.get(@config['repo_key'])
end

#srcdestObject



68
69
70
# File 'lib/akabei/omakase/config.rb', line 68

def srcdest
  Pathname.new(@config['srcdest'])
end

#validate!Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/akabei/omakase/config.rb', line 45

def validate!
  REQUIRED_ATTRIBUTES.each do |attr|
    unless @config.has_key?(attr)
      raise InvalidConfig.new("#{attr.inspect} is required")
    end
  end
  unless @config['builds'].is_a?(Hash)
    raise InvalidConfig.new('"builds" must be a Hash')
  end
  @config['builds'].each do |arch, config_file|
    REQUIRED_BUILD_ATTRIBUTES.each do |attr|
      unless config_file.has_key?(attr)
        raise InvalidConfig.new("builds.#{arch}: #{attr.inspect} is required")
      end
    end
  end
  true
end