Class: Berkshelf::Config
- Inherits:
-
Chozo::Config::JSON
- Object
- Chozo::Config::JSON
- Berkshelf::Config
- Defined in:
- lib/berkshelf/config.rb
Overview
Constant Summary collapse
- FILENAME =
"config.json".freeze
- KNIFE_LOCATIONS =
List taken from: wiki.opscode.com/display/chef/Chef+Configuration+Settings Listed in order of preferred preference
[ './.chef/knife.rb', '~/.chef/knife.rb', '/etc/chef/solo.rb', '/etc/chef/client.rb' ].freeze
Class Method Summary collapse
- .chef_config ⇒ Chef::Config
- .chef_config_path ⇒ String?
- .chef_config_path=(value) ⇒ Object
-
.file ⇒ String?
The contents of the file.
-
.instance ⇒ Config
Instantiate and return or just return the currently instantiated Berkshelf configuration.
- .path ⇒ String
- .path=(new_path) ⇒ Object
-
.reload ⇒ Config
Reload the currently instantiated Berkshelf configuration.
Instance Method Summary collapse
-
#initialize(path = self.class.path, options = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(path = self.class.path, options = {}) ⇒ Config
Returns a new instance of Config.
93 94 95 |
# File 'lib/berkshelf/config.rb', line 93 def initialize(path = self.class.path, = {}) super(path, ) end |
Class Method Details
.chef_config ⇒ Chef::Config
54 55 56 57 58 59 60 61 |
# File 'lib/berkshelf/config.rb', line 54 def chef_config @chef_config ||= begin Chef::Config.from_file(File.(chef_config_path)) Chef::Config rescue Chef::Config end end |
.chef_config_path ⇒ String?
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/berkshelf/config.rb', line 30 def chef_config_path @chef_config_path ||= begin possibles = KNIFE_LOCATIONS.dup unless ENV['BERKSHELF_CHEF_CONFIG'].nil? possibles.unshift(ENV['BERKSHELF_CHEF_CONFIG']) end location = possibles.find do |location| File.exists?(File.(location)) end location ||= "~/.chef/knife.rb" File.(location) end end |
.chef_config_path=(value) ⇒ Object
48 49 50 51 |
# File 'lib/berkshelf/config.rb', line 48 def chef_config_path=(value) @chef_config = nil @chef_config_path = value end |
.file ⇒ String?
Returns the contents of the file.
65 66 67 |
# File 'lib/berkshelf/config.rb', line 65 def file File.read(path) if File.exists?(path) end |
.instance ⇒ Config
Instantiate and return or just return the currently instantiated Berkshelf configuration
73 74 75 76 77 78 79 |
# File 'lib/berkshelf/config.rb', line 73 def instance @instance ||= if file from_json file else new end end |
.path ⇒ String
20 21 22 |
# File 'lib/berkshelf/config.rb', line 20 def path @path || File.join(Berkshelf.berkshelf_path, FILENAME) end |
.path=(new_path) ⇒ Object
25 26 27 |
# File 'lib/berkshelf/config.rb', line 25 def path=(new_path) @path = File.(new_path) end |
.reload ⇒ Config
Reload the currently instantiated Berkshelf configuration
84 85 86 87 |
# File 'lib/berkshelf/config.rb', line 84 def reload @instance = nil self.instance end |