Class: Sumcli::Commands::Add::Service::Postgres

Inherits:
Sumcli::Command show all
Defined in:
lib/sumcli/commands/add/service/postgres.rb

Constant Summary collapse

DOCKER_FILE =
'docker-compose.yml'

Instance Method Summary collapse

Methods inherited from Sumcli::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(name, version, options) ⇒ Postgres

Returns a new instance of Postgres.



13
14
15
16
17
# File 'lib/sumcli/commands/add/service/postgres.rb', line 13

def initialize(name, version, options)
@name = name
@version = version
@options = options
end

Instance Method Details

#add_postgresObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sumcli/commands/add/service/postgres.rb', line 28

def add_postgres
content = 
"db:\n    image: 'postgres:\#{@version}'\n    ports:\n    - '5432'\n"

generator.safe_inject_into_file DOCKER_FILE, content, after: "services:\n"
end

#ask_to_set(ver) ⇒ Object



40
41
42
43
# File 'lib/sumcli/commands/add/service/postgres.rb', line 40

def ask_to_set(ver)
prompt.yes?("The default version of #{@name} is #{ver}." + 
    "\n\nDo you want to add with version #{@version}?")
end

#execute(input: $stdin, output: $stdout) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/sumcli/commands/add/service/postgres.rb', line 19

def execute(input: $stdin, output: $stdout)
generator.copy_file 'lib/sumcli/templates/add/service/database.yml.erb', 
'config/database.yml'
generator.copy_file 'lib/sumcli/templates/add/service/database.yml.ctmpl.erb', 
'config/database.yml.ctmpl'

output.puts "\n  #{@name} added to docker-compose" if self.send("add_#{@name}")
end