Class: Sambot::Config
- Inherits:
-
Object
- Object
- Sambot::Config
- Defined in:
- lib/sambot/config.rb
Constant Summary collapse
- CONFIGURATION_FILENAME =
'.config.yml'
Class Method Summary collapse
Instance Method Summary collapse
- #available_platforms ⇒ Object
- #dependencies ⇒ Object
- #dependencies=(value) ⇒ Object
- #description ⇒ Object
- #forwarded_ports ⇒ Object
- #gems ⇒ Object
- #identifier ⇒ Object
-
#initialize(opts) ⇒ Config
constructor
A new instance of Config.
- #is_role_cookbook? ⇒ Boolean
- #name ⇒ Object
- #runs_on_centos? ⇒ Boolean
- #runs_on_windows? ⇒ Boolean
- #secrets ⇒ Object
- #suites ⇒ Object
- #transform_hashes(obj) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(opts) ⇒ Config
Returns a new instance of Config.
21 22 23 |
# File 'lib/sambot/config.rb', line 21 def initialize(opts) @opts = opts end |
Class Method Details
.bump(version) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/sambot/config.rb', line 97 def self.bump(version) UI.debug("Old cookbook version: #{version}") version_info = Semantic::Version.new version new_version = "#{version_info.major}.#{version_info.minor}.#{version_info.patch + 1}" UI.debug("Old cookbook version: #{new_version}") new_version end |
.bump_version(path = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/sambot/config.rb', line 11 def self.bump_version(path = nil) path ||= File.join(Dir.getwd, CONFIGURATION_FILENAME) contents = File.read(path) version = contents.match(/version: (.+)$/)[1] new_version = bump(version) contents = contents.gsub(version, new_version) File.write(path, contents) new_version end |
.read(path = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sambot/config.rb', line 25 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'].is_a?(Array) config['platform'] = [config['platform']] end config['platforms'] = config['platform'] end Config.new(config) end |
Instance Method Details
#available_platforms ⇒ Object
48 49 50 51 52 |
# File 'lib/sambot/config.rb', line 48 def available_platforms platforms = @opts[:platforms] if @opts.key?(:platforms) platforms = @opts['platforms'] if @opts.key?('platforms') platforms end |
#dependencies ⇒ Object
62 63 64 65 |
# File 'lib/sambot/config.rb', line 62 def dependencies items = @opts['dependencies'] items ? items.map { |x| transform_hashes(x) } : [] end |
#dependencies=(value) ⇒ Object
67 68 69 |
# File 'lib/sambot/config.rb', line 67 def dependencies=(value) @opts['dependencies'] = value end |
#description ⇒ Object
75 |
# File 'lib/sambot/config.rb', line 75 def description; @opts['description']; end |
#forwarded_ports ⇒ Object
54 55 56 |
# File 'lib/sambot/config.rb', line 54 def forwarded_ports @opts['forwarded_ports'] || [] end |
#gems ⇒ Object
58 59 60 |
# File 'lib/sambot/config.rb', line 58 def gems @opts['gems'] || [] end |
#identifier ⇒ Object
77 |
# File 'lib/sambot/config.rb', line 77 def identifier; @opts['identifier']; end |
#is_role_cookbook? ⇒ Boolean
44 45 46 |
# File 'lib/sambot/config.rb', line 44 def is_role_cookbook? name.start_with?('as-role-') || name.start_with?('as-app-role-') end |
#name ⇒ Object
85 |
# File 'lib/sambot/config.rb', line 85 def name; @opts['name']; end |
#runs_on_centos? ⇒ Boolean
87 88 89 |
# File 'lib/sambot/config.rb', line 87 def runs_on_centos? available_platforms.include?('centos') end |
#runs_on_windows? ⇒ Boolean
91 92 93 |
# File 'lib/sambot/config.rb', line 91 def runs_on_windows? available_platforms.include?('windows') end |
#secrets ⇒ Object
83 |
# File 'lib/sambot/config.rb', line 83 def secrets; @opts.dig('local_testing', 'secrets') || []; end |
#suites ⇒ Object
79 |
# File 'lib/sambot/config.rb', line 79 def suites; @opts['suites']; end |
#transform_hashes(obj) ⇒ Object
71 72 73 |
# File 'lib/sambot/config.rb', line 71 def transform_hashes(obj) obj.is_a?(Hash) ? "#{obj.keys.first}', '#{obj.values.first}" : obj end |
#version ⇒ Object
81 |
# File 'lib/sambot/config.rb', line 81 def version; @opts['version']; end |