Class: Harbor::Config
- Inherits:
-
Object
- Object
- Harbor::Config
- Defined in:
- lib/harbor/config.rb
Constant Summary collapse
- SCHEMA_VERSION =
1
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Class Method Summary collapse
Instance Method Summary collapse
- #add_project(name, path, destinations: nil, default_destination: nil, description: nil) ⇒ Object
- #audit_db_path ⇒ Object
- #deploy_timeout ⇒ Object
- #exec_timeout ⇒ Object
-
#initialize(path) ⇒ Config
constructor
A new instance of Config.
- #lock_timeout ⇒ Object
- #logs_timeout ⇒ Object
- #project(name) ⇒ Object
- #projects ⇒ Object
- #remove_project(name) ⇒ Object
- #setting(key, default = nil) ⇒ Object
Constructor Details
#initialize(path) ⇒ Config
Returns a new instance of Config.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/harbor/config.rb', line 17 def initialize(path) @path = path @data = if File.exist?(path) YAML.safe_load_file(path, permitted_classes: [Symbol]) || {} else {} end @data["version"] ||= SCHEMA_VERSION @data["projects"] ||= {} @settings = @data.fetch("settings", {}) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/harbor/config.rb', line 10 def path @path end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
10 11 12 |
# File 'lib/harbor/config.rb', line 10 def settings @settings end |
Class Method Details
.load(path = nil) ⇒ Object
12 13 14 15 |
# File 'lib/harbor/config.rb', line 12 def self.load(path = nil) path ||= DEFAULT_CONFIG_PATH new(path) end |
Instance Method Details
#add_project(name, path, destinations: nil, default_destination: nil, description: nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/harbor/config.rb', line 42 def add_project(name, path, destinations: nil, default_destination: nil, description: nil) full_path = File.(path) config_file = "config/deploy.yml" unless File.directory?(full_path) raise ConfigError, "Path does not exist: #{full_path}" end unless File.exist?(File.join(full_path, config_file)) raise ConfigError, "No deploy.yml found at #{File.join(full_path, config_file)}" end destinations ||= detect_destinations(full_path) @data["projects"][name] = Project.new( name: name, path: full_path, destinations: destinations, default_destination: default_destination || destinations.first, description: description ).to_h save end |
#audit_db_path ⇒ Object
94 95 96 |
# File 'lib/harbor/config.rb', line 94 def audit_db_path setting("audit_db", DEFAULT_AUDIT_DB) end |
#deploy_timeout ⇒ Object
82 83 84 |
# File 'lib/harbor/config.rb', line 82 def deploy_timeout setting("deploy_timeout", 600) # 10 minutes end |
#exec_timeout ⇒ Object
86 87 88 |
# File 'lib/harbor/config.rb', line 86 def exec_timeout setting("exec_timeout", 120) # 2 minutes end |
#lock_timeout ⇒ Object
78 79 80 |
# File 'lib/harbor/config.rb', line 78 def lock_timeout setting("lock_timeout", 1800) # 30 minutes end |
#logs_timeout ⇒ Object
90 91 92 |
# File 'lib/harbor/config.rb', line 90 def logs_timeout setting("logs_timeout", 30) end |
#project(name) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/harbor/config.rb', line 35 def project(name) attrs = @data["projects"][name] raise ProjectNotFound, "Project '#{name}' not found. Run 'harbor list' to see registered projects." unless attrs build_project(name, attrs) end |
#projects ⇒ Object
29 30 31 32 33 |
# File 'lib/harbor/config.rb', line 29 def projects @data["projects"].map do |name, attrs| build_project(name, attrs) end end |
#remove_project(name) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/harbor/config.rb', line 67 def remove_project(name) raise ProjectNotFound, "Project '#{name}' not found." unless @data["projects"].key?(name) @data["projects"].delete(name) save end |
#setting(key, default = nil) ⇒ Object
74 75 76 |
# File 'lib/harbor/config.rb', line 74 def setting(key, default = nil) @settings.fetch(key.to_s, default) end |