Class: FryCook::VagrantPlugin::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/fry_cook/vagrant_plugin/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig



28
29
30
31
32
# File 'lib/fry_cook/vagrant_plugin/config.rb', line 28

def initialize()
  self.class.config_attrs.each do |config_attr, default|
    instance_variable_set(:"@#{config_attr}", UNSET_VALUE)
  end
end

Class Method Details

.config_attr(name, default = nil, &block) ⇒ Object



4
5
6
7
8
# File 'lib/fry_cook/vagrant_plugin/config.rb', line 4

def self.config_attr(name, default = nil, &block)
  @config_attrs ||= {}
  @config_attrs[name] = block || default
  attr_accessor name
end

.config_attrsObject



9
10
11
# File 'lib/fry_cook/vagrant_plugin/config.rb', line 9

def self.config_attrs
  @config_attrs || {}
end

.host_ip_addressObject



12
13
14
15
16
17
18
19
# File 'lib/fry_cook/vagrant_plugin/config.rb', line 12

def self.host_ip_address
  # This gets the first ip address in a private range. With virtualbox,
  # at least, things seem to be routed so that the vm can connect to this
  # IP even if it has nothing to do with vagrant or virtualbox. This may not
  # be an entirely safe assumption, but vagrant doesn't provide any kind of
  # better way to obtain a canonical reachable address as far as I can tell.
  Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.ip_address
end

Instance Method Details

#finalize!Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fry_cook/vagrant_plugin/config.rb', line 34

def finalize!
  self.class.config_attrs.each do |config_attr, default|
    if instance_variable_get(:"@#{config_attr}") == UNSET_VALUE
      if default.respond_to? :call
        default = default.call
      end
      instance_variable_set(:"@#{config_attr}", default)
    end
  end
  {}
end