Class: SqluiConfig

Inherits:
Object
  • Object
show all
Defined in:
app/sqlui_config.rb

Overview

App config including database configs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, overrides = {}) ⇒ SqluiConfig

Returns a new instance of SqluiConfig.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/sqlui_config.rb', line 12

def initialize(filename, overrides = {})
  config = YAML.safe_load(ERB.new(File.read(filename)).result).deep_merge!(overrides)
  config.deep_symbolize_keys!
  @name = Args.fetch_non_empty_string(config, :name).strip
  @port = Args.fetch_non_empty_int(config, :port)
  @environment = Args.fetch_non_empty_string(config, :environment).strip
  @list_url_path = Args.fetch_non_empty_string(config, :list_url_path).strip
  raise ArgumentError, 'list_url_path should start with a /' unless @list_url_path.start_with?('/')
  if @list_url_path.length > 1 && @list_url_path.end_with?('/')
    raise ArgumentError, 'list_url_path should not end with a /'
  end

  databases = Args.fetch_non_empty_hash(config, :databases)
  @database_configs = databases.map do |_, current|
    DatabaseConfig.new(current)
  end
end

Instance Attribute Details

#database_configsObject (readonly)

Returns the value of attribute database_configs.



10
11
12
# File 'app/sqlui_config.rb', line 10

def database_configs
  @database_configs
end

#environmentObject (readonly)

Returns the value of attribute environment.



10
11
12
# File 'app/sqlui_config.rb', line 10

def environment
  @environment
end

#list_url_pathObject (readonly)

Returns the value of attribute list_url_path.



10
11
12
# File 'app/sqlui_config.rb', line 10

def list_url_path
  @list_url_path
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'app/sqlui_config.rb', line 10

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'app/sqlui_config.rb', line 10

def port
  @port
end

Instance Method Details

#database_config_for(url_path:) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
# File 'app/sqlui_config.rb', line 30

def database_config_for(url_path:)
  config = @database_configs.find { |database| database.url_path == url_path }
  raise ArgumentError, "no config found for path #{url_path}" unless config

  config
end