Class: Berkshelf::ChefConfigCompat

Inherits:
Object
  • Object
show all
Defined in:
lib/berkshelf/chef_config_compat.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ ChefConfigCompat

Create a new Chef Config object.

Parameters:

  • path (#to_s)

    the path to the configuration file

  • options (Hash) (defaults to: {})


12
13
14
15
16
# File 'lib/berkshelf/chef_config_compat.rb', line 12

def initialize(path, options = {})
  ChefConfig::WorkstationConfigLoader.new(path).load
  ChefConfig::Config.merge!(options)
  ChefConfig::Config.export_proxies # Set proxy settings as environment variables
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Behave just like ChefConfig::Config in general



42
43
44
# File 'lib/berkshelf/chef_config_compat.rb', line 42

def method_missing(name, *args, &block)
  ChefConfig::Config.send(name, *args, &block)
end

Class Method Details

.from_file(file) ⇒ Object

Load from a file



37
38
39
# File 'lib/berkshelf/chef_config_compat.rb', line 37

def self.from_file(file)
  new(file)
end

Instance Method Details

Keep defaults that aren’t in ChefConfig::Config



19
20
21
# File 'lib/berkshelf/chef_config_compat.rb', line 19

def cookbook_copyright(*args, &block)
  ChefConfig::Config.cookbook_copyright(*args, &block) || "YOUR_NAME"
end

#cookbook_email(*args, &block) ⇒ Object



23
24
25
# File 'lib/berkshelf/chef_config_compat.rb', line 23

def cookbook_email(*args, &block)
  ChefConfig::Config.cookbook_email(*args, &block) || "YOUR_EMAIL"
end

#cookbook_license(*args, &block) ⇒ Object



27
28
29
# File 'lib/berkshelf/chef_config_compat.rb', line 27

def cookbook_license(*args, &block)
  ChefConfig::Config.cookbook_license(*args, &block) || "reserved"
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(name)
  ChefConfig::Config.respond_to?(name)
end

#to_hashObject

The configuration as a hash



32
33
34
# File 'lib/berkshelf/chef_config_compat.rb', line 32

def to_hash
  ChefConfig::Config.save(true)
end