Class: Berkshelf::Config

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

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 Buff::Config::JSON


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/berkshelf/config.rb', line 62

def initialize(path = self.class.path, options = {})
  super(path, options).tap do
    # Deprecation
    if !self.vagrant.omnibus.enabled.nil?
      Berkshelf.ui.warn "`vagrant.omnibus.enabled' is deprecated and " \
        "will be removed in a future release. Please remove the " \
        "`enabled' attribute from your Berkshelf config."
    end
    if !self.vagrant.vm.box_url.nil?
      Berkshelf.ui.warn "`vagrant.vm.box_url' is deprecated and " \
        "will be removed in a future release. Please remove the " \
        "`box_url' attribute from your Berkshelf config."
    end
  end
end

Class Method Details

.fileString?

Returns the contents of the file.

Returns:

  • (String, nil)

    the contents of the file


34
35
36
# File 'lib/berkshelf/config.rb', line 34

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

.instanceConfig

Instantiate and return or just return the currently instantiated Berkshelf configuration

Returns:


42
43
44
45
46
47
48
# File 'lib/berkshelf/config.rb', line 42

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

.local_locationString

Returns:


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

def local_location
  ENV['BERKSHELF_CONFIG'] || File.join('.', '.berkshelf', 'config.json')
end

.pathString

Returns:


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

def path
  path = File.exists?(local_location) ? local_location : store_location
  File.expand_path(path)
end

.reloadConfig

Reload the currently instantiated Berkshelf configuration

Returns:


53
54
55
56
# File 'lib/berkshelf/config.rb', line 53

def reload
  @instance = nil
  self.instance
end

.set_config(config) ⇒ Object

Parameters:


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

def set_config(config)
  @instance = config
end

.set_path(new_path) ⇒ Object

Parameters:


28
29
30
# File 'lib/berkshelf/config.rb', line 28

def set_path(new_path)
  @instance = nil
end

.store_locationString

Returns:


7
8
9
# File 'lib/berkshelf/config.rb', line 7

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