Class: Ridley::Chef::Config

Inherits:
Buff::Config::Ruby
  • Object
show all
Defined in:
lib/ridley/chef/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Create a new Chef Config object.

Parameters:

  • path (#to_s)

    the path to the configuration file

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


82
83
84
# File 'lib/ridley/chef/config.rb', line 82

def initialize(path, options = {})
  super(path || self.class.location, options)
end

Class Method Details

.locationString?

Return the most sensible path to the Chef configuration file. This can be configured by setting a value for the ‘RIDLEY_CHEF_CONFIG’ environment variable.

Returns:

  • (String, nil)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ridley/chef/config.rb', line 12

def location
  possibles = []

  possibles << ENV['RIDLEY_CHEF_CONFIG'] if ENV['RIDLEY_CHEF_CONFIG']
  possibles << File.join(ENV['KNIFE_HOME'], 'knife.rb') if ENV['KNIFE_HOME']
  possibles << File.join(working_dir, 'knife.rb') if working_dir

  # Ascending search for .chef directory siblings
  Pathname.new(working_dir).ascend do |file|
    sibling_chef = File.join(file, '.chef')
    possibles << File.join(sibling_chef, 'knife.rb')
  end if working_dir

  possibles << File.join(ENV['HOME'], '.chef', 'knife.rb') if ENV['HOME']
  possibles.compact!

  location = possibles.find { |loc| File.exists?(File.expand_path(loc)) }

  File.expand_path(location) unless location.nil?
end