Class: VagrantPlugins::Bindfs::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::Bindfs::Config
- Defined in:
- lib/vagrant-bindfs/config.rb
Instance Attribute Summary collapse
-
#bind_folders ⇒ Object
Returns the value of attribute bind_folders.
-
#default_options(new_values = {}) ⇒ Object
Returns the value of attribute default_options.
Instance Method Summary collapse
- #bind_folder(source_path, dest_path, options = {}) ⇒ Object
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #merge(other) ⇒ Object
- #validate!(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
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_folders ⇒ Object
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 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, = {}) [:source_path] = source_path [:dest_path] = dest_path @bind_folders[[:dest_path]] = 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.((other.)) new_folders = bind_folders.dup other_folders = other.bind_folders other_folders.each do |id, | new_folders[id] ||= {} new_folders[id].merge! 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, | next if [:disabled] if [:dest_path].nil? or [:source_path].nil? errors << I18n.t( "vagrant.config.bindfs.errors.no_path_supplied", path: [:dest_path] ) end if Pathname.new([:dest_path]).relative? errors << I18n.t( "vagrant.config.bindfs.errors.destination_path_relative", path: [:dest_path] ) end if Pathname.new([:source_path]).relative? errors << I18n.t( "vagrant.config.bindfs.errors.source_path_relative", path: [: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 |