Class: DatabaseConfig
- Inherits:
-
Object
- Object
- DatabaseConfig
- Defined in:
- app/database_config.rb
Overview
Config for a single database.
Instance Attribute Summary collapse
-
#client_params ⇒ Object
readonly
Returns the value of attribute client_params.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#display_name ⇒ Object
readonly
Returns the value of attribute display_name.
-
#saved_path ⇒ Object
readonly
Returns the value of attribute saved_path.
-
#url_path ⇒ Object
readonly
Returns the value of attribute url_path.
Instance Method Summary collapse
-
#initialize(hash) ⇒ DatabaseConfig
constructor
A new instance of DatabaseConfig.
- #with_client(&block) ⇒ Object
Constructor Details
#initialize(hash) ⇒ DatabaseConfig
Returns a new instance of DatabaseConfig.
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_params ⇒ Object (readonly)
Returns the value of attribute client_params.
8 9 10 |
# File 'app/database_config.rb', line 8 def client_params @client_params end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'app/database_config.rb', line 8 def description @description end |
#display_name ⇒ Object (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_path ⇒ Object (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_path ⇒ Object (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 |