Class: Berkshelf::Config
- Inherits:
-
Chozo::Config::JSON
- Object
- Chozo::Config::JSON
- Berkshelf::Config
- Defined in:
- lib/berkshelf/config.rb
Constant Summary collapse
- LOCATIONS =
[ File.join('.', '.berkshelf', 'config.json').freeze, File.join('.', 'berkshelf', 'config.json').freeze, File.join('.', 'berkshelf-config.json').freeze, File.join('.', 'config.json').freeze ].freeze
Class Method Summary collapse
- .default_location ⇒ String
-
.file ⇒ String?
The contents of the file.
-
.instance ⇒ Config
Instantiate and return or just return the currently instantiated Berkshelf configuration.
- .path ⇒ String
-
.reload ⇒ Config
Reload the currently instantiated Berkshelf configuration.
- .set_path(new_path) ⇒ Object
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.
66 67 68 |
# File 'lib/berkshelf/config.rb', line 66 def initialize(path = self.class.path, = {}) super(path, ) end |
Class Method Details
.default_location ⇒ String
14 15 16 |
# File 'lib/berkshelf/config.rb', line 14 def default_location File.join(Berkshelf.berkshelf_path, 'config.json') end |
.file ⇒ String?
Returns the contents of the file.
38 39 40 |
# File 'lib/berkshelf/config.rb', line 38 def file File.read(path) if File.exists?(path) end |
.instance ⇒ Config
Instantiate and return or just return the currently instantiated Berkshelf configuration
46 47 48 49 50 51 52 |
# File 'lib/berkshelf/config.rb', line 46 def instance @instance ||= if file from_json file else new end end |
.path ⇒ String
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/berkshelf/config.rb', line 19 def path @path ||= begin location = LOCATIONS.find do |file| path = File.(file) File.exists?(path) end File.(location || default_location) end end |
.reload ⇒ Config
Reload the currently instantiated Berkshelf configuration
57 58 59 60 |
# File 'lib/berkshelf/config.rb', line 57 def reload @instance = nil self.instance end |
.set_path(new_path) ⇒ Object
31 32 33 34 |
# File 'lib/berkshelf/config.rb', line 31 def set_path(new_path) @instance = nil @path = File.(new_path) end |