Class: Sambot::Config

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

Constant Summary collapse

CONFIGURATION_FILENAME =
'.config.yml'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Config

Returns a new instance of Config.



20
21
22
# File 'lib/sambot/config.rb', line 20

def initialize(opts)
  @opts = opts
end

Class Method Details

.bump_version(path = nil) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/sambot/config.rb', line 11

def self.bump_version(path = nil)
  path ||= File.join(Dir.getwd, CONFIGURATION_FILENAME)
  config = YAML.load_file(path)
  version = config['version']
  config['version'] = bump(version)
  File.write(path, YAML.dump(config))
  config['version']
end

.read(path = nil) ⇒ Object

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sambot/config.rb', line 24

def self.read(path = nil)
  path ||= File.join(Dir.getwd, CONFIGURATION_FILENAME)
  raise ApplicationError, "The configuration file was not found at #{path}." unless File.exist?(path)
  config = YAML.load_file(path)
  raise ApplicationError, 'Missing cookbook name in the .config.yml configuration file' unless config['name']
  raise ApplicationError, 'Missing platforms in the .config.yml configuration file' unless config['platform'] || config['platforms']
  raise ApplicationError, 'Missing version in the .config.yml configuration file' unless config['version']
  raise ApplicationError, 'Missing list of suites in the .config.yml configuration file' unless config['suites']
  raise ApplicationError, 'Missing description in the .config.yml configuration file' unless config['description']
  # Dealing with legacy tech debt of allowing multiple platforms rather than a single platform
  unless config['platforms']
    unless config['platform'].kind_of?(Array)
      config['platform'] = [config['platform']]
    end
    config['platforms'] = config['platform']
  end
  Config.new(config)
end

Instance Method Details

#available_platformsObject



43
44
45
46
47
# File 'lib/sambot/config.rb', line 43

def available_platforms
  platforms = @opts[:platforms] if @opts.has_key?(:platforms)
  platforms = @opts['platforms'] if @opts.has_key?('platforms')
  platforms
end

#dependenciesObject



53
54
55
56
# File 'lib/sambot/config.rb', line 53

def dependencies
  items = @opts['dependencies'] || @opts[:dependencies]
  items ? items.map { |x| transform_hashes(x) } : []
end

#dependencies=(value) ⇒ Object



58
59
60
# File 'lib/sambot/config.rb', line 58

def dependencies=(value)
  @opts['dependencies'] = value
end

#descriptionObject



66
# File 'lib/sambot/config.rb', line 66

def description; @opts['description']; end

#gemsObject



49
50
51
# File 'lib/sambot/config.rb', line 49

def gems
  @opts['gems'] || @opts[:gems] || []
end

#identifierObject



68
# File 'lib/sambot/config.rb', line 68

def identifier; @opts['identifier']; end

#nameObject



76
# File 'lib/sambot/config.rb', line 76

def name; @opts['name']; end

#runs_on_centos?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/sambot/config.rb', line 78

def runs_on_centos?
  available_platforms.include?('centos')
end

#runs_on_windows?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/sambot/config.rb', line 82

def runs_on_windows?
  available_platforms.include?('windows')
end

#secretsObject



74
# File 'lib/sambot/config.rb', line 74

def secrets; @opts['local_testing']['secrets']; end

#suitesObject



70
# File 'lib/sambot/config.rb', line 70

def suites; @opts['suites']; end

#transform_hashes(obj) ⇒ Object



62
63
64
# File 'lib/sambot/config.rb', line 62

def transform_hashes(obj)
  obj.is_a?(Hash) ? "#{obj.keys.first}', '#{obj.values.first}" : obj
end

#versionObject



72
# File 'lib/sambot/config.rb', line 72

def version; @opts['version']; end