Class: Ridley::Chef::Config
- Inherits:
-
Buff::Config::Ruby
- Object
- Buff::Config::Ruby
- Ridley::Chef::Config
- Defined in:
- lib/ridley/chef/config.rb
Class Method Summary collapse
-
.location ⇒ String?
Return the most sensible path to the Chef configuration file.
Instance Method Summary collapse
-
#initialize(path, options = {}) ⇒ Config
constructor
Create a new Chef Config object.
Constructor Details
#initialize(path, options = {}) ⇒ Config
Create a new Chef Config object.
82 83 84 |
# File 'lib/ridley/chef/config.rb', line 82 def initialize(path, = {}) super(path || self.class.location, ) end |
Class Method Details
.location ⇒ String?
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.
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.(loc)) } File.(location) unless location.nil? end |