Class: SqluiConfig
- Inherits:
-
Object
- Object
- SqluiConfig
- Defined in:
- app/sqlui_config.rb
Overview
App config including database configs.
Instance Attribute Summary collapse
-
#airbrake ⇒ Object
readonly
Returns the value of attribute airbrake.
-
#base_url_path ⇒ Object
readonly
Returns the value of attribute base_url_path.
-
#database_configs ⇒ Object
readonly
Returns the value of attribute database_configs.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #database_config_for(url_path:) ⇒ Object
-
#initialize(filename, overrides = {}) ⇒ SqluiConfig
constructor
A new instance of SqluiConfig.
Constructor Details
#initialize(filename, overrides = {}) ⇒ SqluiConfig
Returns a new instance of SqluiConfig.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/sqlui_config.rb', line 13 def initialize(filename, overrides = {}) config = YAML.safe_load(ERB.new(File.read(filename)).result, aliases: true).deep_merge!(overrides) config.deep_symbolize_keys! # Dup since if anchors are used some keys might refer to the same object. If we end up modifying an object, # we don't want it to be modified in multiple places. config = config.deep_dup @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 @base_url_path = Args.fetch_non_empty_string(config, :base_url_path).strip raise ArgumentError, 'base_url_path should start with a /' unless @base_url_path.start_with?('/') if @base_url_path.length > 1 && @base_url_path.end_with?('/') raise ArgumentError, 'base_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 @airbrake = Args.fetch_optional_hash(config, :airbrake) || { enabled: false } end |
Instance Attribute Details
#airbrake ⇒ Object (readonly)
Returns the value of attribute airbrake.
11 12 13 |
# File 'app/sqlui_config.rb', line 11 def airbrake @airbrake end |
#base_url_path ⇒ Object (readonly)
Returns the value of attribute base_url_path.
11 12 13 |
# File 'app/sqlui_config.rb', line 11 def base_url_path @base_url_path end |
#database_configs ⇒ Object (readonly)
Returns the value of attribute database_configs.
11 12 13 |
# File 'app/sqlui_config.rb', line 11 def database_configs @database_configs end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
11 12 13 |
# File 'app/sqlui_config.rb', line 11 def environment @environment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'app/sqlui_config.rb', line 11 def name @name end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'app/sqlui_config.rb', line 11 def port @port end |
Instance Method Details
#database_config_for(url_path:) ⇒ Object
35 36 37 38 39 40 |
# File 'app/sqlui_config.rb', line 35 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 |