Class: Berkshelf::Config

Inherits:
Chozo::Config::JSON
  • Object
show all
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

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



66
67
68
# File 'lib/berkshelf/config.rb', line 66

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

Class Method Details

.default_locationString

Returns:



14
15
16
# File 'lib/berkshelf/config.rb', line 14

def default_location
  File.join(Berkshelf.berkshelf_path, 'config.json')
end

.fileString?

Returns the contents of the file.

Returns:

  • (String, nil)

    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

.instanceConfig

Instantiate and return or just return the currently instantiated Berkshelf configuration

Returns:



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

.pathString

Returns:



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.expand_path(file)
      File.exists?(path)
    end

    File.expand_path(location || default_location)
  end
end

.reloadConfig

Reload the currently instantiated Berkshelf configuration

Returns:



57
58
59
60
# File 'lib/berkshelf/config.rb', line 57

def reload
  @instance = nil
  self.instance
end

.set_path(new_path) ⇒ Object

Parameters:



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

def set_path(new_path)
  @instance = nil
  @path     = File.expand_path(new_path)
end