Class: Seira::Db
- Inherits:
-
Object
- Object
- Seira::Db
- Defined in:
- lib/seira/db.rb,
lib/seira/db/create.rb
Defined Under Namespace
Classes: Create
Constant Summary collapse
- VALID_ACTIONS =
%w[help create delete list restart connect].freeze
- SUMMARY =
"Manage your Cloud SQL Postgres databases.".freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#initialize(app:, action:, args:, context:) ⇒ Db
constructor
A new instance of Db.
-
#primary_instance ⇒ Object
NOTE: Relies on the pgbouncer instance being named based on the db name, as is done in create command.
- #run ⇒ Object
Constructor Details
#initialize(app:, action:, args:, context:) ⇒ Db
Returns a new instance of Db.
12 13 14 15 16 17 |
# File 'lib/seira/db.rb', line 12 def initialize(app:, action:, args:, context:) @app = app @action = action @args = args @context = context end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
10 11 12 |
# File 'lib/seira/db.rb', line 10 def action @action end |
#app ⇒ Object (readonly)
Returns the value of attribute app.
10 11 12 |
# File 'lib/seira/db.rb', line 10 def app @app end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
10 11 12 |
# File 'lib/seira/db.rb', line 10 def args @args end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
10 11 12 |
# File 'lib/seira/db.rb', line 10 def context @context end |
Instance Method Details
#primary_instance ⇒ Object
NOTE: Relies on the pgbouncer instance being named based on the db name, as is done in create command
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/seira/db.rb', line 39 def primary_instance database_url = Secrets.new(app: app, action: 'get', args: [], context: context).get('DATABASE_URL') return nil unless database_url primary_uri = URI.parse(database_url) host = primary_uri.host # Convert handshake-onyx-burmese-pgbouncer-service to handshake-onyx-burmese host.gsub('-pgbouncer-service', '') end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/seira/db.rb', line 19 def run case action when 'help' run_help when 'create' run_create when 'delete' run_delete when 'list' run_list when 'restart' run_restart when 'connect' run_connect else fail "Unknown command encountered" end end |