Class: VagrantPlugins::Bindfs::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

def initialize
  @default_options = UNSET_VALUE
  @bind_folders = {}

  @logger = Log4r::Logger.new('vagrantplugins::bindfs::config')
end

Instance Attribute Details

#bind_foldersObject

Returns the value of attribute bind_folders.



8
9
10
# File 'lib/vagrant-bindfs/config.rb', line 8

def bind_folders
  @bind_folders
end

#default_options(new_values = {}) ⇒ Object

Returns the value of attribute default_options.



8
9
10
# File 'lib/vagrant-bindfs/config.rb', line 8

def default_options
  @default_options
end

Instance Method Details

#bind_folder(source_path, dest_path, options = {}) ⇒ Object



22
23
24
25
26
27
# File 'lib/vagrant-bindfs/config.rb', line 22

def bind_folder(source_path, dest_path, options = {})
  options[:source_path] = source_path
  options[:dest_path] = dest_path

  @bind_folders[options[:dest_path]] = options
end

#finalize!Object



45
46
47
# File 'lib/vagrant-bindfs/config.rb', line 45

def finalize!
  @default_options = {} if @default_options == UNSET_VALUE
end

#merge(other) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vagrant-bindfs/config.rb', line 29

def merge(other)
  super.tap do |result|
    result.default_options(default_options(other.default_options))

    new_folders = bind_folders.dup
    other_folders = other.bind_folders

    other_folders.each do |id, options|
      new_folders[id] ||= {}
      new_folders[id].merge! options
    end

    result.bind_folders = new_folders
  end
end

#validate!(machine) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/vagrant-bindfs/config.rb', line 49

def validate!(machine)
  finalize!
  errors = []

  bind_folders.each do |id, options|
    next if options[:disabled]

    if options[:dest_path].nil? or options[:source_path].nil?
      errors << I18n.t(
        "vagrant.config.bindfs.errors.no_path_supplied",
        path: options[:dest_path]
      )
    end

    if Pathname.new(options[:dest_path]).relative?
      errors << I18n.t(
        "vagrant.config.bindfs.errors.destination_path_relative",
        path: options[:dest_path]
      )
    end

    if Pathname.new(options[:source_path]).relative?
      errors << I18n.t(
        "vagrant.config.bindfs.errors.source_path_relative",
        path: options[:source_path]
      )
    end
  end

  if errors.any?
    rendered_errors = Vagrant::Util::TemplateRenderer.render(
      'config/validation_failed',
      errors: { 'vagrant-bindfs' => errors }
    )

    fail Vagrant::Errors::ConfigInvalid, errors: rendered_errors
  end
end