Class: Vagrant::Config::V2::DummyConfig

Inherits:
Plugin::V2::Config show all
Defined in:
lib/vagrant/config/v2/dummy_config.rb

Overview

This is a configuration object that can have anything done to it. Anything, and it just appears to keep working.

Constant Summary collapse

LOG =
Log4r::Logger.new("vagrant::config::v2::dummy_config")

Constants inherited from Plugin::V2::Config

Plugin::V2::Config::UNSET_VALUE

Instance Method Summary collapse

Methods inherited from Plugin::V2::Config

#_detected_errors, #_finalize!, #clean_up_config_object, #finalize!, #to_json, #to_s, #validate

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vagrant/config/v2/dummy_config.rb', line 12

def method_missing(name, *args, &block)
  # There are a few scenarios where ruby will attempt to implicity
  # coerce a given object into a certain type. DummyConfigs can end up
  # in some of these scenarios when they're being shipped around in
  # callbacks with splats. If method_missing allows these methods to be
  # called but continues to return DummyConfig back, Ruby will raise a
  # TypeError. Doing the normal thing of raising NoMethodError allows
  # DummyConfig to behave normally as its being passed through splats.
  #
  # For a bit more detail and some keywords for further searching, see:
  # https://ruby-doc.org/core-2.7.2/doc/implicit_conversion_rdoc.html
  if [:to_hash, :to_ary].include?(name)
    return super
  end

  # Trying to define a variable
  if name.to_s.match(/^[\w]*=/)
    LOG.debug("found name #{name}")
    LOG.debug("setting instance variable name #{name.to_s.split("=")[0]}")
    var_name = "@#{name.to_s.split("=")[0]}"
    self.instance_variable_set(var_name, args[0])
  else
    DummyConfig.new
  end
end

Instance Method Details

#instance_variables_hashObject



51
52
53
54
55
56
# File 'lib/vagrant/config/v2/dummy_config.rb', line 51

def instance_variables_hash
  instance_variables.inject({}) do |acc, iv|
    acc[iv.to_s[1..-1]] = instance_variable_get(iv)
    acc
  end
end

#merge(c) ⇒ Object



38
39
40
# File 'lib/vagrant/config/v2/dummy_config.rb', line 38

def merge(c)
  c
end

#set_options(options) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/vagrant/config/v2/dummy_config.rb', line 42

def set_options(options)
  options.each do |key, value|
    if key.to_s.match(/^[\w]*=/)
      var_name = "@#{key.to_s}"
      self.instance_variable_set(var_name, value)
    end
  end
end