Class: Berkshelf::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/berkshelf/config.rb
Defined Under Namespace
Modules: BerksConfig
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path = self.class.path) ⇒ Config
Returns a new instance of Config.
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/berkshelf/config.rb', line 98
def initialize(path = self.class.path)
@klass = Class.new
@klass.extend(Mixlib::Config)
@klass.extend(BerksConfig)
@path = File.expand_path(path)
@klass.from_file(@path) if File.exist?(@path)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
111
112
113
|
# File 'lib/berkshelf/config.rb', line 111
def method_missing(method, *args, &block)
@klass.send(method, *args, &block)
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
95
96
97
|
# File 'lib/berkshelf/config.rb', line 95
def path
@path
end
|
Class Method Details
.coerce_ssl ⇒ Config
force proper X509 types from any configuration strings
74
75
76
77
78
79
80
|
# File 'lib/berkshelf/config.rb', line 74
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
|
Returns the contents of the file.
45
46
47
|
# File 'lib/berkshelf/config.rb', line 45
def file
File.read(path) if File.exist?(path)
end
|
.from_file(path) ⇒ Object
82
83
84
|
# File 'lib/berkshelf/config.rb', line 82
def from_file(path)
new(path)
end
|
.from_hash(hash) ⇒ Object
90
91
92
|
# File 'lib/berkshelf/config.rb', line 90
def from_hash(hash)
new.from_hash(hash)
end
|
.from_json(json) ⇒ Object
86
87
88
|
# File 'lib/berkshelf/config.rb', line 86
def from_json(json)
new.from_json(json)
end
|
Instantiate and return or just return the currently instantiated Berkshelf configuration
53
54
55
56
57
58
59
60
61
|
# File 'lib/berkshelf/config.rb', line 53
def instance
@instance ||=
if file
from_json file
else
new
end
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
|
28
29
30
31
|
# File 'lib/berkshelf/config.rb', line 28
def path
path = File.exist?(local_location) ? local_location : store_location
File.expand_path(path)
end
|
Reload the currently instantiated Berkshelf configuration
66
67
68
69
|
# File 'lib/berkshelf/config.rb', line 66
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
|