Class: FPM::Cookery::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/fpm/cookery/config.rb

Constant Summary collapse

ATTRIBUTES =
[
  :color, :debug, :target, :platform, :maintainer, :vendor,
  :skip_package, :keep_destdir, :dependency_check, :quiet,
  :tmp_root, :pkg_dir, :cache_dir
].freeze
DEFAULTS =
{
  :color => true,
  :debug => false,
  :dependency_check => true,
  :skip_package => false,
  :keep_destdir => false,
  :quiet => false
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Config

Returns a new instance of Config.



54
55
56
57
58
59
60
# File 'lib/fpm/cookery/config.rb', line 54

def initialize(data = {})
  validate_input(data)

  DEFAULTS.merge(data).each do |key, value|
    self.__send__("#{key}=", value)
  end
end

Class Method Details

.from_cli(cli) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fpm/cookery/config.rb', line 28

def self.from_cli(cli)
  new.tap do |config|
    ATTRIBUTES.each do |name|
      if cli.respond_to?("#{name}?")
        value = cli.__send__("#{name}?")
      elsif cli.respond_to?(name)
        value = cli.__send__(name)
      else
        value = nil
      end

      config.__send__("#{name}=", value) unless value.nil?
    end
  end
end

.load_file(paths) ⇒ Object



22
23
24
25
26
# File 'lib/fpm/cookery/config.rb', line 22

def self.load_file(paths)
  path = Array(paths).find {|p| File.exist?(p) }

  path ? new(YAML.load_file(path)) : new
end

Instance Method Details

#to_hashObject



62
63
64
65
66
67
# File 'lib/fpm/cookery/config.rb', line 62

def to_hash
  ATTRIBUTES.inject({}) do |hash, attribute|
    hash[attribute] = __send__(attribute)
    hash
  end
end