Module: Berkshelf::Mixin::Config::ClassMethods

Defined in:
lib/berkshelf/mixin/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_location(path) ⇒ String? (readonly)

Returns:



46
47
48
# File 'lib/berkshelf/mixin/config.rb', line 46

def default_location(path)
  @default_location = File.expand_path(path)
end

Instance Method Details

#default_option(option, value) ⇒ Object

Class method for defining a default option.

Parameters:

  • option (#to_sym)

    the symbol to store as the key

  • value (Object)

    the return value



31
32
33
# File 'lib/berkshelf/mixin/config.rb', line 31

def default_option(option, value)
  default_options[option.to_sym] = value
end

#default_optionsHash

A list of all the default options set by this class.

Returns:

  • (Hash)


38
39
40
# File 'lib/berkshelf/mixin/config.rb', line 38

def default_options
  @default_options ||= {}
end

#from_file(filepath) ⇒ Object

Load a Chef configuration from the given path.

Raises:



13
14
15
16
17
# File 'lib/berkshelf/mixin/config.rb', line 13

def from_file(filepath)
  self.new(filepath)
rescue Errno::ENOENT => e
  raise Berkshelf::ConfigNotFound.new(self.class.name, filepath)
end

#loadObject

Load the contents of the most probable Chef config. See #location for more information on how this logic is decided.



21
22
23
# File 'lib/berkshelf/mixin/config.rb', line 21

def load
  self.new(location)
end

#platform_specific_path(path) ⇒ String

Converts a path to a path usable for your current platform

Parameters:

Returns:



58
59
60
61
62
63
64
65
# File 'lib/berkshelf/mixin/config.rb', line 58

def platform_specific_path(path)
  if RUBY_PLATFORM =~ /mswin|mingw|windows/
    system_drive = ENV['SYSTEMDRIVE'] ? ENV['SYSTEMDRIVE'] : ""
    path         = win_slashify File.join(system_drive, path.split('/')[2..-1])
  end

  path
end