Class: Dockerploy::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/dockerploy/template.rb

Constant Summary collapse

TEMPLATE_PATH =
'templates/config.yml.erb'.freeze
CONFIG_PATH =
'docker/config.yml.sample'.freeze

Class Method Summary collapse

Class Method Details

.application_nameObject



6
7
8
# File 'lib/dockerploy/template.rb', line 6

def self.application_name
  File.basename(Dir.getwd)
end

.generateObject



16
17
18
19
20
# File 'lib/dockerploy/template.rb', line 16

def self.generate
  namespace = OpenStruct.new(user: ENV['USER'], application_name: self.application_name, project_name: self.project_name)
  template = File.read(File.expand_path(TEMPLATE_PATH, File.dirname(__FILE__)))
  ERB.new(template).result(namespace.instance_eval { binding })
end

.project_nameObject



10
11
12
13
14
# File 'lib/dockerploy/template.rb', line 10

def self.project_name
  shell_client = ShellClient.new
  shell_client.command('git config --get remote.origin.url')
  shell_client.output.match(/([\w-]+\/[\w-]+).git/)[1]
end

.writeObject



22
23
24
25
# File 'lib/dockerploy/template.rb', line 22

def self.write
  FileUtils.mkdir_p('docker')
  File.open(CONFIG_PATH, 'w') { |f| f.write(self.generate) }
end