Class: VagrantBindfs::Vagrant::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 17

def initialize
  @debug = false

  @bindfs_version = UNSET_VALUE
  @install_bindfs_from_source = false

  @bound_folders = {}
  @default_options = Bindfs::OptionSet.new(nil,
                                           'force-user' => 'vagrant',
                                           'force-group' => 'vagrant',
                                           'perms' => 'u=rwX:g=rD:o=rD')

  @skip_validations = []
  @force_empty_mountpoints = false
end

Instance Attribute Details

#bindfs_versionObject

Returns the value of attribute bindfs_version.



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

def bindfs_version
  @bindfs_version
end

#bound_foldersObject

Returns the value of attribute bound_folders.



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

def bound_folders
  @bound_folders
end

#debugObject

Returns the value of attribute debug.



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

def debug
  @debug
end

#default_optionsObject

Returns the value of attribute default_options.



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

def default_options
  @default_options
end

#force_empty_mountpointsObject

Returns the value of attribute force_empty_mountpoints.



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

def force_empty_mountpoints
  @force_empty_mountpoints
end

#install_bindfs_from_sourceObject

Returns the value of attribute install_bindfs_from_source.



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

def install_bindfs_from_source
  @install_bindfs_from_source
end

#skip_validationsObject

Returns the value of attribute skip_validations.



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

def skip_validations
  @skip_validations
end

Instance Method Details

#bind_folder(source, destination, options = {}) ⇒ Object



57
58
59
60
61
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 57

def bind_folder(source, destination, options = {})
  hook = options.delete(:after) || :synced_folders
  folder = Bindfs::Folder.new(hook, source, destination, options)
  @bound_folders[folder.id] = folder
end

#bound_folder=(*_any_variant) ⇒ Object



53
54
55
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 53

def bound_folder=(*_any_variant)
  raise VagrantBindfs::Vagrant::ConfigError, :bound_folders
end

#finalize!Object



79
80
81
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 79

def finalize!
  @bindfs_version = :latest if @bindfs_version == UNSET_VALUE
end

#merge(other) ⇒ Object

rubocop:disable Metrics/AbcSize



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 63

def merge(other) # rubocop:disable Metrics/AbcSize
  super.tap do |result|
    result.debug = (debug || other.debug)

    result_bindfs_version = [bindfs_version, other.bindfs_version].reject { |v| v == UNSET_VALUE }.min
    result.bindfs_version = result_bindfs_version unless result_bindfs_version.nil?
    result.install_bindfs_from_source = (install_bindfs_from_source || other.install_bindfs_from_source)

    result.default_options = default_options.merge(other.default_options)
    result.bound_folders = bound_folders.merge(other.bound_folders)

    result.skip_validations = (skip_validations + other.skip_validations).uniq
    result.force_empty_mountpoints = (force_empty_mountpoints || other.force_empty_mountpoints)
  end
end

#source_version=(value) ⇒ Object



37
38
39
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 37

def source_version=(value)
  @bindfs_version = Gem::Version.new(value.to_s)
end

#validate(_machine) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 83

def validate(_machine)
  errors = _detected_errors

  bound_folders.each_value do |folder|
    validator = Bindfs::Validators::Config.new(folder)
    errors << validator.errors unless validator.valid?
  end

  { 'vagrant-bindfs' => errors.flatten }
end