Class: Naifa::Config

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

Constant Summary collapse

SETTINGS_VERSION =
1.1
DEFAULT_SETTINGS =
{
  db: {
    :plugin => :postgres
  },
  s3: {
    :plugin => :s3
  }
}.with_indifferent_access.freeze

Class Method Summary collapse

Class Method Details

.generate_example_settingsObject



26
27
28
29
30
31
32
# File 'lib/naifa/config.rb', line 26

def self.generate_example_settings
  full_settings = {'version' => SETTINGS_VERSION}.with_indifferent_access
    .merge(DEFAULT_SETTINGS)
  full_settings[:db][:settings] = Naifa::Plugins::Postgres::DEFAULT_SETTINGS
  full_settings[:s3][:settings] = Naifa::Plugins::S3::DEFAULT_SETTINGS
  full_settings.to_hash
end

.settingsObject



16
17
18
19
20
21
22
23
24
# File 'lib/naifa/config.rb', line 16

def self.settings
  @settings ||= begin
    loaded_settings = YAML.load(File.read('.naifa')).with_indifferent_access if File.exists?('.naifa')
    if !loaded_settings.nil? && loaded_settings.delete(:version) != SETTINGS_VERSION
      raise 'Configuration file version is not supported. Please upgrade!'
    end
    loaded_settings
  end || {}
end

.sub_commandsObject



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

def self.sub_commands
  settings.keys
end