Class: Berkshelf::Config
- Inherits:
-
Object
- Object
- Berkshelf::Config
- Defined in:
- lib/berkshelf/config.rb
Defined Under Namespace
Modules: BerksConfig
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
-
.coerce_ssl ⇒ Config
force proper X509 types from any configuration strings.
- .from_file(path) ⇒ Object
-
.instance ⇒ Config
Instantiate and return or just return the currently instantiated Berkshelf configuration.
- .local_location ⇒ String
- .path ⇒ String
-
.reload ⇒ Config
Reload the currently instantiated Berkshelf configuration.
- .set_config(config) ⇒ Object
- .set_path(new_path) ⇒ Object
- .store_location ⇒ String
Instance Method Summary collapse
-
#initialize(path = self.class.path) ⇒ Config
constructor
A new instance of Config.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(path = self.class.path) ⇒ Config
Returns a new instance of Config.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/berkshelf/config.rb', line 79 def initialize(path = self.class.path) # this is a bit tricky, mixlib-config wants to extend a class and create effectively a global config object while # what we want to do is use an instance, so we create an anonymous class and shove it into an instance variable. # this is actually similar to what mixlib-config itself does to create config contexts. @klass = Class.new @klass.extend(Mixlib::Config) @klass.extend(BerksConfig) @path = File.(path) @klass.from_file(@path) if File.exist?(@path) # yeah, if !File.exist?() you just get back an empty config object Berkshelf.ui.warn "The `cookbook.copyright' config is deprecated and will be removed in a future release." unless cookbook.copyright.nil? Berkshelf.ui.warn "The `cookbook.email' config is deprecated and will be removed in a future release." unless cookbook.email.nil? Berkshelf.ui.warn "The `cookbook.license' config is deprecated and will be removed in a future release." unless cookbook.license.nil? Berkshelf.ui.warn "The `vagrant.vm.box' config is deprecated and will be removed in a future release." unless vagrant.vm.box.nil? Berkshelf.ui.warn "The `vagrant.vm.forward_port' config is deprecated and will be removed in a future release." unless vagrant.vm.forward_port.nil? Berkshelf.ui.warn "The `vagrant.vm.provision' config is deprecated and will be removed in a future release." unless vagrant.vm.provision.nil? Berkshelf.ui.warn "The `vagrant.vm.omnibus.version' config is deprecated and will be removed in a future release." unless vagrant.vm.omnibus.version.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
100 101 102 |
# File 'lib/berkshelf/config.rb', line 100 def method_missing(method, *args, &block) @klass.send(method, *args, &block) end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
76 77 78 |
# File 'lib/berkshelf/config.rb', line 76 def path @path end |
Class Method Details
.coerce_ssl ⇒ Config
force proper X509 types from any configuration strings
63 64 65 66 67 68 69 |
# File 'lib/berkshelf/config.rb', line 63 def coerce_ssl ssl = @instance[:ssl] ssl[:ca_cert] = OpenSSL::X509::Certificate.new(File.read(ssl[:ca_cert])) if ssl[:ca_cert] && ssl[:ca_cert].is_a?(String) ssl[:client_cert] = OpenSSL::X509::Certificate.new(File.read(ssl[:client_cert])) if ssl[:client_cert] && ssl[:client_cert].is_a?(String) ssl[:client_key] = OpenSSL::PKey::RSA.new(File.read(ssl[:client_key])) if ssl[:client_key] && ssl[:client_key].is_a?(String) @instance end |
.from_file(path) ⇒ Object
71 72 73 |
# File 'lib/berkshelf/config.rb', line 71 def from_file(path) new(path) end |
.instance ⇒ Config
Instantiate and return or just return the currently instantiated Berkshelf configuration
47 48 49 50 |
# File 'lib/berkshelf/config.rb', line 47 def instance @instance ||= new(path) coerce_ssl end |
.local_location ⇒ String
23 24 25 |
# File 'lib/berkshelf/config.rb', line 23 def local_location ENV["BERKSHELF_CONFIG"] || File.join(".", ".berkshelf", "config.json") end |
.path ⇒ String
28 29 30 31 |
# File 'lib/berkshelf/config.rb', line 28 def path path = File.exist?(local_location) ? local_location : store_location File.(path) end |
.reload ⇒ Config
Reload the currently instantiated Berkshelf configuration
55 56 57 58 |
# File 'lib/berkshelf/config.rb', line 55 def reload @instance = nil instance end |
.set_config(config) ⇒ Object
34 35 36 |
# File 'lib/berkshelf/config.rb', line 34 def set_config(config) @instance = config end |
.set_path(new_path) ⇒ Object
39 40 41 |
# File 'lib/berkshelf/config.rb', line 39 def set_path(new_path) @instance = nil end |
.store_location ⇒ String
18 19 20 |
# File 'lib/berkshelf/config.rb', line 18 def store_location File.join(Berkshelf.berkshelf_path, "config.json") end |