Class: MFYNAB::Config

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

Constant Summary collapse

DEFAULT_MONTHS_TO_SYNC =
3

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_config, logger) ⇒ Config

Returns a new instance of Config.



9
10
11
12
# File 'lib/mfynab/config.rb', line 9

def initialize(hash_config, logger)
  @hash_config = hash_config
  @logger = logger
end

Class Method Details

.from_yaml(file, logger) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mfynab/config.rb', line 14

def self.from_yaml(file, logger)
  yaml_data = YAML.load_file(file)
  # Backwards compatibility: support old config files that still have a top-level key.
  # TODO: at some point (major version bump), we should probably remove this.
  unless yaml_data.key?("accounts")
    logger.warn("Top-level key in configuration file is deprecated. Please remove it.")
    yaml_data = yaml_data.values.first
  end

  raise "Invalid configuration file" unless yaml_data.key?("accounts")

  new(yaml_data, logger)
end

Instance Method Details

#accountsObject



36
37
38
# File 'lib/mfynab/config.rb', line 36

def accounts
  hash_config.fetch("accounts", [])
end

#credentialsObject



40
41
42
# File 'lib/mfynab/config.rb', line 40

def credentials
  @_credentials ||= CredentialsNormalizer.new(hash_config, logger).normalize
end

#months_to_syncObject



32
33
34
# File 'lib/mfynab/config.rb', line 32

def months_to_sync
  hash_config.fetch("months_to_sync", DEFAULT_MONTHS_TO_SYNC)
end

#ynab_budgetObject



28
29
30
# File 'lib/mfynab/config.rb', line 28

def ynab_budget
  hash_config.fetch("ynab_budget")
end