Class: VagrantPlugins::YarrsAndYamls::Plugin::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-yarrs-and-yamls/command.rb

Instance Method Summary collapse

Instance Method Details

#backup_file(source) ⇒ Object



39
40
41
42
# File 'lib/vagrant-yarrs-and-yamls/command.rb', line 39

def backup_file(source)
    dest = timestamp_filename(source)
    FileUtils.mv source, dest, :force => true if File.exists? source
end

#copy_file(source, dest) ⇒ Object



33
34
35
36
37
# File 'lib/vagrant-yarrs-and-yamls/command.rb', line 33

def copy_file(source, dest)
    source = File.realpath(source)
    backup_file(dest)
    FileUtils.copy_file source, dest
end

#create_vagrant_fileObject



21
22
23
24
25
# File 'lib/vagrant-yarrs-and-yamls/command.rb', line 21

def create_vagrant_file
    source = File.expand_path('../../../Vagrantfile.example', __FILE__)
    dest = Dir.pwd + '/Vagrantfile'
    copy_file source, dest
end

#create_yaml_file(file) ⇒ Object



27
28
29
30
31
# File 'lib/vagrant-yarrs-and-yamls/command.rb', line 27

def create_yaml_file(file)
    source = File.expand_path('../../../Yarrs.example.yaml', __FILE__)
    dest = Dir.pwd + "/#{file}"
    copy_file source, dest
end

#executeObject



12
13
14
15
16
17
18
19
# File 'lib/vagrant-yarrs-and-yamls/command.rb', line 12

def execute
  create_vagrant_file
  create_yaml_file("Yarrs.yaml")

  @env.ui.success("yarrs-and-yamls: Successfully created Yarrs.yaml file!")
  @env.ui.success("yarrs-and-yamls: Next step - edit Yarrs.yaml then vagrant up")
  0
end

#synopsisObject



8
9
10
# File 'lib/vagrant-yarrs-and-yamls/command.rb', line 8

def synopsis
  "generates a starter Yarrs.yaml"
end

#timestamp_filename(file) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/vagrant-yarrs-and-yamls/command.rb', line 44

def timestamp_filename(file)
    dir  = File.dirname(file)
    base = File.basename(file, ".*")
    time = Time.now.to_i
    ext  = File.extname(file)
    File.join(dir, "#{base}.bak.#{time}#{ext}")
end