Class: VagrantSpec::Command::Init

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/vagrant_spec/command/init.rb

Overview

This command instantiates serveral files for deployment and testing

argv env [Vagrant::Environment]

Constant Summary collapse

DEFAULTS =
VagrantSpec::Config::DEFAULTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#lib_root, #project_root, #template_dir

Constructor Details

#initialize(argv, env) ⇒ Init



19
20
21
22
23
24
# File 'lib/vagrant_spec/command/init.rb', line 19

def initialize(argv, env)
  super
  @config            = VagrantSpec::Config.load env
  @directory         = @config.spec.directory
  @ansible_inventory = @config.spec.ansible_inventory
end

Instance Attribute Details

#ansible_inventoryObject

Returns the value of attribute ansible_inventory.



18
19
20
# File 'lib/vagrant_spec/command/init.rb', line 18

def ansible_inventory
  @ansible_inventory
end

#configObject

Returns the value of attribute config.



18
19
20
# File 'lib/vagrant_spec/command/init.rb', line 18

def config
  @config
end

#directoryObject

Returns the value of attribute directory.



18
19
20
# File 'lib/vagrant_spec/command/init.rb', line 18

def directory
  @directory
end

Instance Method Details

#executeObject



26
27
28
29
30
31
32
# File 'lib/vagrant_spec/command/init.rb', line 26

def execute
  return unless parse_opts
  VagrantSpec::SpecHelper.new(@env).generate
  unless @ansible_inventory == DEFAULTS['ansible_inventory']
    VagrantSpec::AnsibleInventory.new(@env).generate
  end
end

#parse_optsObject



34
35
36
37
38
39
40
41
42
# File 'lib/vagrant_spec/command/init.rb', line 34

def parse_opts
  opts = OptionParser.new do |o|
    o.banner = "\nCreates the serverspec/spec_helper.rb file for testing"
    o.separator ''
    o.separator 'Usage: vagrant spec init'
    o.separator ''
  end
  parse_options(opts)
end