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.



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

def initialize
  @debug                      = false

  @bindfs_version             = UNSET_VALUE
  @install_bindfs_from_source = false

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

  @skip_validations           = []
end

Instance Attribute Details

#binded_foldersObject

Returns the value of attribute binded_folders.



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

def binded_folders
  @binded_folders
end

#bindfs_versionObject

Returns the value of attribute bindfs_version.



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

def bindfs_version
  @bindfs_version
end

#debugObject

Returns the value of attribute debug.



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

def debug
  @debug
end

#default_optionsObject

Returns the value of attribute default_options.



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

def default_options
  @default_options
end

#install_bindfs_from_sourceObject

Returns the value of attribute install_bindfs_from_source.



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

def install_bindfs_from_source
  @install_bindfs_from_source
end

#skip_validationsObject

Returns the value of attribute skip_validations.



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

def skip_validations
  @skip_validations
end

Instance Method Details

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



49
50
51
52
53
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 49

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

#binded_folder=(*_any_variant) ⇒ Object



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

def binded_folder=(*_any_variant)
  raise VagrantBindfs::Vagrant::ConfigError, :binded_folders
end

#finalize!Object



70
71
72
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 70

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

#merge(other) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 55

def merge(other)
  super.tap do |result|
    result.debug                      = (debug || other.debug)

    result_bindfs_version             = [bindfs_version, other.bindfs_version].select { |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.binded_folders             = binded_folders.merge(other.binded_folders)

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

#source_version=(value) ⇒ Object



33
34
35
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 33

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

#validate(_machine) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/vagrant-bindfs/vagrant/config.rb', line 74

def validate(_machine)
  errors = _detected_errors

  binded_folders.each do |_, folder|
    validator = Bindfs::Validators::Config.new(folder)
    errors << validator.errors unless validator.valid?
  end

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