Class: Berkshelf::Config

Inherits:
Chozo::Config::JSON
  • Object
show all
Defined in:
lib/berkshelf/config.rb

Overview

Author:

Constant Summary collapse

FILENAME =
"config.json".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Config.

Parameters:

  • path (String) (defaults to: self.class.path)
  • options (Hash) (defaults to: {})

    @see Chozo::Config::JSON



50
51
52
# File 'lib/berkshelf/config.rb', line 50

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

Class Method Details

.fileString?

Returns the contents of the file.

Returns:

  • (String, nil)

    the contents of the file



22
23
24
# File 'lib/berkshelf/config.rb', line 22

def file
  File.read(path) if File.exists?(path)
end

.instanceConfig

Instantiate and return or just return the currently instantiated Berkshelf configuration

Returns:



30
31
32
33
34
35
36
# File 'lib/berkshelf/config.rb', line 30

def instance
  @instance ||= if file
    from_json file
  else
    new
  end
end

.pathString

Returns:



11
12
13
# File 'lib/berkshelf/config.rb', line 11

def path
  @path || File.join(Berkshelf.berkshelf_path, FILENAME)
end

.path=(new_path) ⇒ Object

Parameters:



16
17
18
# File 'lib/berkshelf/config.rb', line 16

def path=(new_path)
  @path = File.expand_path(new_path)
end

.reloadConfig

Reload the currently instantiated Berkshelf configuration

Returns:



41
42
43
44
# File 'lib/berkshelf/config.rb', line 41

def reload
  @instance = nil
  self.instance
end