Class: VagrantPlugins::Fabric::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-fabric/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



9
10
11
12
13
14
# File 'lib/vagrant-fabric/config.rb', line 9

def initialize
  @fabfile_path = UNSET_VALUE
  @fabric_path  = UNSET_VALUE
  @python_path  = UNSET_VALUE
  @tasks        = UNSET_VALUE
end

Instance Attribute Details

#fabfile_pathObject

Returns the value of attribute fabfile_path.



4
5
6
# File 'lib/vagrant-fabric/config.rb', line 4

def fabfile_path
  @fabfile_path
end

#fabric_pathObject

Returns the value of attribute fabric_path.



5
6
7
# File 'lib/vagrant-fabric/config.rb', line 5

def fabric_path
  @fabric_path
end

#python_pathObject

Returns the value of attribute python_path.



6
7
8
# File 'lib/vagrant-fabric/config.rb', line 6

def python_path
  @python_path
end

#tasksObject

Returns the value of attribute tasks.



7
8
9
# File 'lib/vagrant-fabric/config.rb', line 7

def tasks
  @tasks
end

Instance Method Details

#execute(command) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vagrant-fabric/config.rb', line 23

def execute(command)
  output = ''
  begin
    IO.popen(command, "w+") do |f|
      f.close_write
      output = f.read
    end
    output
  rescue Errno::ENOENT
    false
  end
end

#finalize!Object



16
17
18
19
20
21
# File 'lib/vagrant-fabric/config.rb', line 16

def finalize!
  @fabfile_path = "fabfile.py" if @fabfile_path == UNSET_VALUE
  @fabric_path = "fab" if @fabric_path == UNSET_VALUE
  @python_path = "python" if @python_path == UNSET_VALUE
  @tasks = [] if @tasks == UNSET_VALUE
end

#validate(env) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vagrant-fabric/config.rb', line 36

def validate(env)
  errors = _detected_errors

  errors << "fabfile does not exist." if not File.exist?(fabfile_path)

  command = "#{fabric_path} -V"
  output = execute(command)
  errors << "fabric command does not exist." if not output

  command = "#{fabric_path} -f #{fabfile_path} -l"
  output = execute(command)
  errors << "#{fabfile_path} could not recognize by fabric." if not $?.success?

  for task in tasks
    task = task.split(':').first
    command = "#{fabric_path} -f #{fabfile_path} -d #{task}"
    output = execute(command)
    errors << "#{task} task does not exist." if not $?.success?
  end

  { "fabric provisioner" => errors }
end