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
  @debug = 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

#debugObject

Returns the value of attribute debug.



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

def debug
  @debug
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
28
# 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
  options[:hook] ||= options.delete(:after) || VagrantPlugins::Bindfs::Plugin.hook_names.first

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

#finalize!Object



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

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

#merge(other) ⇒ Object



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

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



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
87
88
89
90
91
92
93
94
95
# File 'lib/vagrant-bindfs/config.rb', line 51

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

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

    unless VagrantPlugins::Bindfs::Plugin.hook_names.include?(options[:hook].to_sym)
      errors << I18n.t(
          "vagrant.config.bindfs.errors.invalid_hook",
          hooks: VagrantPlugins::Bindfs::Plugin.hook_names
      )
    end

    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