Class: Deploio::PgDatabaseResolver
- Inherits:
-
Object
- Object
- Deploio::PgDatabaseResolver
- Defined in:
- lib/deploio/pg_database_resolver.rb
Instance Attribute Summary collapse
-
#current_org ⇒ Object
readonly
Returns the value of attribute current_org.
-
#nctl ⇒ Object
readonly
Returns the value of attribute nctl.
Instance Method Summary collapse
-
#available_databases_hash ⇒ Object
Returns hash mapping database names -> app_name:.
-
#initialize(nctl_client:) ⇒ PgDatabaseResolver
constructor
A new instance of PgDatabaseResolver.
- #resolve(database_name: nil) ⇒ Object
- #short_name_for(namespace, database_name) ⇒ Object
Constructor Details
#initialize(nctl_client:) ⇒ PgDatabaseResolver
Returns a new instance of PgDatabaseResolver.
7 8 9 10 |
# File 'lib/deploio/pg_database_resolver.rb', line 7 def initialize(nctl_client:) @nctl = nctl_client @current_org = @nctl.current_org end |
Instance Attribute Details
#current_org ⇒ Object (readonly)
Returns the value of attribute current_org.
5 6 7 |
# File 'lib/deploio/pg_database_resolver.rb', line 5 def current_org @current_org end |
#nctl ⇒ Object (readonly)
Returns the value of attribute nctl.
5 6 7 |
# File 'lib/deploio/pg_database_resolver.rb', line 5 def nctl @nctl end |
Instance Method Details
#available_databases_hash ⇒ Object
Returns hash mapping database names -> app_name:
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/deploio/pg_database_resolver.rb', line 21 def available_databases_hash @available_apps_hash ||= begin hash = {} current_org = @nctl.current_org @nctl.get_all_pg_databases.each do |database| = database["metadata"] || {} project_name = ["namespace"] || "" database_name = ["name"] full_name = "#{project_name}-#{database_name}" hash[full_name] = {project_name: project_name, database_name: database_name} # Also index by short name (without org prefix) for convenience if current_org && project_name.start_with?("#{current_org}-") project = project_name.delete_prefix("#{current_org}-") short_name = "#{project}-#{database_name}" hash[short_name] ||= {project_name: project_name, database_name: database_name} end end hash end rescue {} end |
#resolve(database_name: nil) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/deploio/pg_database_resolver.rb', line 12 def resolve(database_name: nil) if database_name return PgDatabaseRef.new(database_name, available_databases: available_databases_hash) end raise Deploio::Error, "No database specified" end |
#short_name_for(namespace, database_name) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/deploio/pg_database_resolver.rb', line 45 def short_name_for(namespace, database_name) org = current_org if org && namespace.start_with?("#{org}-") project = namespace.delete_prefix("#{org}-") "#{project}-#{database_name}" else "#{namespace}-#{database_name}" end end |