lib/cloud/sh/config.rb in cloud-sh-1.0.1 vs lib/cloud/sh/config.rb in cloud-sh-1.0.2
- old
+ new
@@ -1,21 +1,25 @@
# frozen_string_literal: true
module Cloud
module Sh
class Config
- attr_reader :accounts
+ attr_reader :accounts, :raw
def initialize
@accounts = []
read_config
end
def read_config
return unless File.exist?(config_file)
- config = YAML.safe_load(File.read(config_file))
- config.each do |account_config|
+ @raw = YAML.safe_load(File.read(config_file))
+ load_accounts
+ end
+
+ def load_accounts
+ raw["accounts"].each do |account_config|
accounts << Account.new(account_config)
end
end
def config_file
@@ -54,14 +58,14 @@
databases << Database.new(database_config)
end
end
def find_cluster(name)
- clusters.find { |cluster| cluster.name == name }
+ clusters.find { |cluster| cluster.name == name } || clusters.push(Cluster.new("name" => name)).last
end
def find_database(name)
- databases.find { |database| database.name == name }
+ databases.find { |database| database.name == name } || databases.push(Database.new("name" => name)).last
end
def ignore_database?(name)
databases.any? do |database|
database.name == name && database.ignore