Class: Nvoi::Configuration::Database
- Inherits:
-
Object
- Object
- Nvoi::Configuration::Database
- Defined in:
- lib/nvoi/configuration/database.rb
Overview
Database defines database configuration
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#image ⇒ Object
Returns the value of attribute image.
-
#mount ⇒ Object
Returns the value of attribute mount.
-
#path ⇒ Object
Returns the value of attribute path.
-
#secrets ⇒ Object
Returns the value of attribute secrets.
-
#servers ⇒ Object
Returns the value of attribute servers.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(data = nil) ⇒ Database
constructor
A new instance of Database.
- #mysql? ⇒ Boolean
- #postgres? ⇒ Boolean
- #sqlite? ⇒ Boolean
- #to_service_spec(namer) ⇒ Object
Constructor Details
#initialize(data = nil) ⇒ Database
Returns a new instance of Database.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/nvoi/configuration/database.rb', line 9 def initialize(data = nil) data ||= {} @servers = data["servers"] || [] @adapter = data["adapter"] @url = data["url"] @image = data["image"] @mount = data["mount"] || {} @secrets = data["secrets"] || {} @path = data["path"] end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/nvoi/configuration/database.rb', line 7 def adapter @adapter end |
#image ⇒ Object
Returns the value of attribute image.
7 8 9 |
# File 'lib/nvoi/configuration/database.rb', line 7 def image @image end |
#mount ⇒ Object
Returns the value of attribute mount.
7 8 9 |
# File 'lib/nvoi/configuration/database.rb', line 7 def mount @mount end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/nvoi/configuration/database.rb', line 7 def path @path end |
#secrets ⇒ Object
Returns the value of attribute secrets.
7 8 9 |
# File 'lib/nvoi/configuration/database.rb', line 7 def secrets @secrets end |
#servers ⇒ Object
Returns the value of attribute servers.
7 8 9 |
# File 'lib/nvoi/configuration/database.rb', line 7 def servers @servers end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/nvoi/configuration/database.rb', line 7 def url @url end |
Instance Method Details
#mysql? ⇒ Boolean
24 25 26 |
# File 'lib/nvoi/configuration/database.rb', line 24 def mysql? @adapter&.downcase == "mysql" end |
#postgres? ⇒ Boolean
20 21 22 |
# File 'lib/nvoi/configuration/database.rb', line 20 def postgres? @adapter&.downcase&.start_with?("postgres") end |
#sqlite? ⇒ Boolean
28 29 30 |
# File 'lib/nvoi/configuration/database.rb', line 28 def sqlite? @adapter&.downcase&.start_with?("sqlite") end |
#to_service_spec(namer) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/nvoi/configuration/database.rb', line 32 def to_service_spec(namer) return nil if @adapter&.downcase&.start_with?("sqlite") port = case @adapter&.downcase when "mysql" then 3306 else 5432 end image = @image || Utils::Constants::DATABASE_IMAGES[@adapter&.downcase] Configuration::Deployment.new( name: namer.database_service_name, image:, port:, env: nil, mounts: @mount, replicas: 1, stateful_set: true, secrets: @secrets, servers: @servers ) end |