Class: Ridoku::Services::Postgres

Inherits:
Object
  • Object
show all
Defined in:
lib/ridoku/services/postgres.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#postgresqlObject

Returns the value of attribute postgresql.



8
9
10
# File 'lib/ridoku/services/postgres.rb', line 8

def postgresql
  @postgresql
end

Instance Method Details

#config(sub) ⇒ Object



38
39
40
# File 'lib/ridoku/services/postgres.rb', line 38

def config(sub)
  $stderr.puts ''
end


23
24
25
26
27
28
29
30
31
# File 'lib/ridoku/services/postgres.rb', line 23

def print_help
  $stderr.puts <<-EOF
Command: service postgres

List/Modify the current app's associated workers.
  postgres[:config]   lists configuration

  EOF
end

#run(cmd, args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ridoku/services/postgres.rb', line 10

def run(cmd, args)
  sub_command = args.shift

  case cmd
  when 'config'
    config(sub_command)
  when 'describe', 'list', 'show', nil
    show(sub_command)
  else
    print_help
  end
end

#setupObject



33
34
35
36
# File 'lib/ridoku/services/postgres.rb', line 33

def setup
  Ridoku::Base.fetch_stack
  self.postgresql = (Base.custom_json['postgresql'] ||= {})
end

#show(sub) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/ridoku/services/postgres.rb', line 65

def show(sub)
  setup

  if sub == 'url'
    return show_url
  end

  $stdout.puts 'Postgresql configuration:'
  puts JSON.pretty_generate(postgresql)
end

#show_urlObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ridoku/services/postgres.rb', line 42

def show_url()
  Ridoku::Base.fetch_app
  Ridoku::Base.fetch_instance('postgresql', force: true)

  app = Ridoku::Base.app[:shortname]
  dbase = postgresql['databases'].select do |db|
    db['app'] == app
  end.first

  unless dbase
    $stderr.puts "Application #{$stderr.colorize('app', :red)} has no "\
      "databases configured."
    return
  end

  dbase['adapter'] = 'postgres'
  dbase['password'] = dbase['user_password']
  dbase['port'] = postgresql['config']['port']
  dbase['host'] = Ridoku::Base.instances.first[:public_ip]

  $stdout.puts $stdout.colorize(Ridoku::Db.gen_dbase_url(dbase), :bold)
end