Class: Specify::Configuration::DBConfig
- Defined in:
- lib/specify/configuration/db_config.rb
Overview
DBConfigs are Specify:Database configurations.
Instance Attribute Summary collapse
-
#database ⇒ Object
The name of the Specify database.
-
#host ⇒ Object
The name of the MySQL/MariaDB host for the Specify database.
-
#port ⇒ Object
The port for the MySQL/MariaDB server for the Specify database.
-
#session_user ⇒ Object
An existing Specify::Model::User#name; the name of the Specify::Model::User that is logged in to #collection during a Session.
-
#user_name ⇒ Object
The MySQL/MariaDB user for the database.
Attributes inherited from Config
Instance Method Summary collapse
-
#changed_password? ⇒ Boolean
Returns
true
if the user_password attribute differs from the:password
in the #params of the YAML file. -
#changed_port? ⇒ Boolean
Returns
true
if #port differs from the:port
in the #params of the YAML file. -
#changed_session_user? ⇒ Boolean
Returns
true
if the #session_user differs from the:so_user
in the #params of the YAML file. -
#changed_user? ⇒ Boolean
Returns
true
if #user_name differs from the user:name
in the #params of the YAML file. -
#connection ⇒ Object
Returns the connection paramaters for the database as a Hash.
-
#db_user ⇒ Object
Returns a Hash with the MySQL/MariaDB user name and password.
-
#host? ⇒ Boolean
Returns
true
if #host is known (has been configured),false
otherwise. -
#initialize(host, database, file = nil) ⇒ DBConfig
constructor
Returns a new DBConfig for
database
onhost
. -
#known? ⇒ Boolean
Returns
true
if #database is known (has been configured),false
otherwise. -
#params ⇒ Object
Returns a Hash with the parameters for the #host #database from the configuration YAML file.
-
#save ⇒ Object
Saves the current state to the YAML file.
-
#user_password=(password) ⇒ Object
Sets the MySQL/MariaDB user_password.
Methods inherited from Config
#add_database, #add_host, empty, #saved?, #touch
Constructor Details
#initialize(host, database, file = nil) ⇒ DBConfig
Returns a new DBConfig for database
on host
file: the YAML file (path) containg the configuration.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/specify/configuration/db_config.rb', line 27 def initialize(host, database, file = nil) super(file) @host = host @database = database @port = hosts.dig @host, :port @user_name = params&.dig :db_user, :name @user_password = params&.dig :db_user, :password @session_user = params&.fetch :sp_user, nil @saved = known? ? true : false end |
Instance Attribute Details
#database ⇒ Object
The name of the Specify database.
8 9 10 |
# File 'lib/specify/configuration/db_config.rb', line 8 def database @database end |
#host ⇒ Object
The name of the MySQL/MariaDB host for the Specify database.
11 12 13 |
# File 'lib/specify/configuration/db_config.rb', line 11 def host @host end |
#port ⇒ Object
The port for the MySQL/MariaDB server for the Specify database.
14 15 16 |
# File 'lib/specify/configuration/db_config.rb', line 14 def port @port end |
#session_user ⇒ Object
An existing Specify::Model::User#name; the name of the Specify::Model::User that is logged in to #collection during a Session.
22 23 24 |
# File 'lib/specify/configuration/db_config.rb', line 22 def session_user @session_user end |
#user_name ⇒ Object
The MySQL/MariaDB user for the database. This is typically the Specify master user.
18 19 20 |
# File 'lib/specify/configuration/db_config.rb', line 18 def user_name @user_name end |
Instance Method Details
#changed_password? ⇒ Boolean
Returns true
if the user_password attribute differs from the :password
in the #params of the YAML file.
55 56 57 |
# File 'lib/specify/configuration/db_config.rb', line 55 def changed_password? params[:db_user][:password] != @user_password end |
#changed_port? ⇒ Boolean
Returns true
if #port differs from the :port
in the #params of the YAML file.
61 62 63 |
# File 'lib/specify/configuration/db_config.rb', line 61 def changed_port? hosts[host][:port] != port end |
#changed_session_user? ⇒ Boolean
Returns true
if the #session_user differs from the :so_user
in the #params of the YAML file.
67 68 69 |
# File 'lib/specify/configuration/db_config.rb', line 67 def changed_session_user? params[:sp_user] != session_user end |
#changed_user? ⇒ Boolean
Returns true
if #user_name differs from the user :name
in the #params of the YAML file.
49 50 51 |
# File 'lib/specify/configuration/db_config.rb', line 49 def changed_user? params[:db_user][:name] != user_name end |
#connection ⇒ Object
Returns the connection paramaters for the database as a Hash.
39 40 41 42 43 44 45 |
# File 'lib/specify/configuration/db_config.rb', line 39 def connection raise "#{database} on #{host} not configured" unless known? { host: host, port: port || 3306, user: user_name, password: @user_password } end |
#db_user ⇒ Object
Returns a Hash with the MySQL/MariaDB user name and password.
78 79 80 |
# File 'lib/specify/configuration/db_config.rb', line 78 def db_user { name: @user_name, password: @user_password } end |
#host? ⇒ Boolean
Returns true
if #host is known (has been configured), false
otherwise.
90 91 92 |
# File 'lib/specify/configuration/db_config.rb', line 90 def host? hosts[host] end |
#known? ⇒ Boolean
Returns true
if #database is known (has been configured), false
otherwise.
96 97 98 |
# File 'lib/specify/configuration/db_config.rb', line 96 def known? params ? true : false end |
#params ⇒ Object
Returns a Hash with the parameters for the #host #database from the configuration YAML file.
102 103 104 |
# File 'lib/specify/configuration/db_config.rb', line 102 def params super.dig:hosts, @host, :databases, @database end |
#save ⇒ Object
Saves the current state to the YAML file.
114 115 116 117 118 |
# File 'lib/specify/configuration/db_config.rb', line 114 def save return true if saved? host? ? update_host : save_new_host super end |
#user_password=(password) ⇒ Object
Sets the MySQL/MariaDB user_password.
133 134 135 136 |
# File 'lib/specify/configuration/db_config.rb', line 133 def user_password=(password) @user_password = password touch end |