Class: MFYNAB::Config
- Inherits:
-
Object
- Object
- MFYNAB::Config
- Defined in:
- lib/mfynab/config.rb
Constant Summary collapse
- DEFAULT_MONTHS_TO_SYNC =
3
Class Method Summary collapse
Instance Method Summary collapse
- #accounts ⇒ Object
- #credentials ⇒ Object
-
#initialize(hash_config, logger) ⇒ Config
constructor
A new instance of Config.
- #months_to_sync ⇒ Object
- #ynab_budget ⇒ Object
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
#accounts ⇒ Object
36 37 38 |
# File 'lib/mfynab/config.rb', line 36 def accounts hash_config.fetch("accounts", []) end |
#credentials ⇒ Object
40 41 42 |
# File 'lib/mfynab/config.rb', line 40 def credentials @_credentials ||= CredentialsNormalizer.new(hash_config, logger).normalize end |
#months_to_sync ⇒ Object
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_budget ⇒ Object
28 29 30 |
# File 'lib/mfynab/config.rb', line 28 def ynab_budget hash_config.fetch("ynab_budget") end |