Class: DatabaseConfig

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

Overview

Config for a single database.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ DatabaseConfig

Returns a new instance of DatabaseConfig.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
# File 'app/database_config.rb', line 10

def initialize(hash)
  @display_name = Args.fetch_non_empty_string(hash, :display_name).strip
  @description = Args.fetch_non_empty_string(hash, :description).strip
  @url_path = Args.fetch_non_empty_string(hash, :url_path).strip
  raise ArgumentError, 'url_path should start with a /' unless @url_path.start_with?('/')
  raise ArgumentError, 'url_path should not end with a /' if @url_path.length > 1 && @url_path.end_with?('/')

  @saved_path = Args.fetch_non_empty_string(hash, :saved_path).strip
  @client_params = Args.fetch_non_empty_hash(hash, :client_params)
end

Instance Attribute Details

#client_paramsObject (readonly)

Returns the value of attribute client_params.



8
9
10
# File 'app/database_config.rb', line 8

def client_params
  @client_params
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'app/database_config.rb', line 8

def description
  @description
end

#display_nameObject (readonly)

Returns the value of attribute display_name.



8
9
10
# File 'app/database_config.rb', line 8

def display_name
  @display_name
end

#saved_pathObject (readonly)

Returns the value of attribute saved_path.



8
9
10
# File 'app/database_config.rb', line 8

def saved_path
  @saved_path
end

#url_pathObject (readonly)

Returns the value of attribute url_path.



8
9
10
# File 'app/database_config.rb', line 8

def url_path
  @url_path
end

Instance Method Details

#with_client(&block) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'app/database_config.rb', line 21

def with_client(&block)
  client = Mysql2::Client.new(@client_params)
  result = block.call(client)
  client.close
  client = nil
  result
ensure
  client&.close
end