Class: HDeploy::Conf
- Inherits:
-
Object
- Object
- HDeploy::Conf
- Defined in:
- lib/hdeploy/conf.rb
Constant Summary collapse
- @@instance =
nil- @@default_values =
[]
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
-
.instance(path = nil) ⇒ Object
FIXME: find a good way to set default path.
Instance Method Summary collapse
-
#[](k) ⇒ Object
————————————————————————-.
-
#add_defaults(h) ⇒ Object
————————————————————————-.
-
#initialize(file) ⇒ Conf
constructor
A new instance of Conf.
-
#reload ⇒ Object
————————————————————————-.
Constructor Details
#initialize(file) ⇒ Conf
Returns a new instance of Conf.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hdeploy/conf.rb', line 13 def initialize(file) # this is for omnibus and such # not very elegant but it works... if file.nil? f = __FILE__ if f.start_with? '/opt/hdeploy/' file = '/opt/hdeploy/hdeploy.json' elsif f.start_with? '/opt/hdeploy-server/' file = '/opt/hdeploy-server/hdeploy-server.json' else file = './hdeploy.json' end end @file = file reload end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
11 12 13 |
# File 'lib/hdeploy/conf.rb', line 11 def file @file end |
Class Method Details
.instance(path = nil) ⇒ Object
FIXME: find a good way to set default path
33 34 35 |
# File 'lib/hdeploy/conf.rb', line 33 def self.instance(path = nil) @@instance ||= new(path) end |
Instance Method Details
#[](k) ⇒ Object
53 54 55 |
# File 'lib/hdeploy/conf.rb', line 53 def [](k) @conf[k] end |
#add_defaults(h) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/hdeploy/conf.rb', line 58 def add_defaults(h) # This is pretty crappy code in that it loads stuff twice etc. But that way no re-implementing a variation of deep_merge for default stuff... @@default_values << h.__deep_clone__ rebuild_conf = {} @@default_values.each do |defval| rebuild_conf.deep_merge!(defval) end @conf = rebuild_conf.deep_merge!(@conf) end |
#reload ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hdeploy/conf.rb', line 39 def reload raise "unable to find conf file #{@file}" unless File.exists? @file st = File.stat(@file) raise "config file #{@file} must not be a symlink" if File.symlink?(@file) raise "config file #{@file} must be a regular file" unless st.file? raise "config file #{@file} must have uid 0" unless st.uid == 0 or Process.uid != 0 raise "config file #{@file} must not allow group/others to write" unless sprintf("%o", st.mode) =~ /^100[46][04][04]/ # Seems we have checked everything. Woohoo! @conf = JSON.parse(File.read(@file)) end |