Class: VagrantPlugins::Bindfs::Config

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

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

def initialize
  @__default_options = {}
  @__bind_folders = {}
end

Instance Method Details

#bind_folder(source_path, dest_path, options = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/vagrant-bindfs/config.rb', line 18

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

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

#bind_foldersObject



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

def bind_folders
  @__bind_folders
end

#default_options(new_options = {}) ⇒ Object



14
15
16
# File 'lib/vagrant-bindfs/config.rb', line 14

def default_options(new_options = {})
  @__default_options.merge! new_options
end

#merge(other) ⇒ Object



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

def merge(other)
  super.tap do |result|
    # merge the changes to default options
    result.instance_variable_set(
      :@__default_options, default_options(other.default_options))

    # merge the folders to be bound
    new_folders = @__bind_folders.dup
    other_folders = other.instance_variable_get(:@__bind_folders)

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

    result.instance_variable_set(:@__bind_folders, new_folders)
  end
end

#validate(machine) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vagrant-bindfs/config.rb', line 45

def validate(machine)
  errors = []

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

    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

  errors.empty? && {} || { 'bindfs' => errors }
end