Class: Config

Inherits:
Object
  • Object
show all
Defined in:
lib/r5/config.rb

Constant Summary collapse

REQUIRED_STRUCTURE =
{'mysql' => {'user' => 'name',
                                  'password' => 'password',
                                  'host' => 'localhost'},
                      'admin' => {'login' => 'admin',
                                  'password' => 'password',
                                  'email' => '[email protected]',
                                  'lastname' => 'administrator'},
                      'notifier' => {'email' => '[email protected]'},
                      'server' => {'name_prod' => 'production server',
                                   'name_stage' => 'stage server',
                                   'port' => 'ssh port',
                                   'user' => 'user name'}
}

Class Method Summary collapse

Class Method Details

.all_keys(hash) ⇒ Object



33
34
35
# File 'lib/r5/config.rb', line 33

def self.all_keys(hash)
  hash.flat_map { |k, v| [k] + (v.is_a?(Hash) ? all_keys(v) : []) }
end

.check_settingsObject

TODO Space for improving structure check - now it is very simple and won’t work properly for duplicated keys in deeper structure



29
30
31
# File 'lib/r5/config.rb', line 29

def self.check_settings
  all_keys(REQUIRED_STRUCTURE) - all_keys(settings)
end

.settingsObject



19
20
21
22
23
24
25
# File 'lib/r5/config.rb', line 19

def self.settings
  if File.exists? "#{ENV['HOME']}/.r5.yml"
    YAML::load_file("#{ENV['HOME']}/.r5.yml")
  else
    'You need to create ~/.r5.yml file, check github for example.'
  end
end