Class: Berkshelf::Chef::Config
- Inherits:
-
Object
- Object
- Berkshelf::Chef::Config
- Extended by:
- Mixin::PathHelpers, Mixlib::Config
- Defined in:
- lib/berkshelf/chef/config.rb
Overview
Inspired by and a dependency-free replacement for https://raw.github.com/opscode/chef/11.4.0/lib/chef/config.rb
Class Method Summary collapse
-
.instance ⇒ Berkshelf::Chef::Config
Load and return a Chef::Config for Berkshelf.
-
.path ⇒ String?
Return the most sensible path to the Chef configuration file.
-
.path=(value) ⇒ Object
Set the path the Chef configuration can be found in.
Methods included from Mixin::PathHelpers
platform_specific_path, win_slashify
Class Method Details
.instance ⇒ Berkshelf::Chef::Config
Load and return a Chef::Config for Berkshelf. The location of the configuration to be loaded can be configured by setting a value for path=
16 17 18 19 20 21 22 23 |
# File 'lib/berkshelf/chef/config.rb', line 16 def instance @instance ||= begin self.from_file(File.(path)) self rescue self end end |
.path ⇒ String?
Return the most sensible path to the Chef configuration file. This can be configured by setting a value for the ‘BERKSHELF_CHEF_CONFIG’ environment variable.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/berkshelf/chef/config.rb', line 29 def path @path ||= begin possibles = [] possibles << ENV['BERKSHELF_CHEF_CONFIG'] if ENV['BERKSHELF_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 end |
.path=(value) ⇒ Object
Set the path the Chef configuration can be found in
55 56 57 58 |
# File 'lib/berkshelf/chef/config.rb', line 55 def path=(value) @instance = nil @path = value end |