Class: FindSubscriptions::ConfigLoader
- Inherits:
-
Object
- Object
- FindSubscriptions::ConfigLoader
- Defined in:
- lib/find_subscriptions/config_loader.rb
Overview
Loads user configuration from a YAML file registered via –set-config.
The pointer file (~/.find-subscriptions-config-path) stores the path to the actual config YAML. ConfigLoader.load returns a Result with parsed options and any user-defined schema definitions.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- CONFIG_POINTER_PATH =
File.('~/.find-subscriptions-config-path').freeze
- STRING_KEYS =
Config YAML keys grouped by how they should be parsed. Amounts stay as strings so BigDecimal conversion happens at the filter site.
%w[sort format schema inactive_for].freeze
- BOOL_KEYS =
%w[filter_known_payees].freeze
- PATH_KEYS =
expanded via File.expand_path
%w[known_payees_path].freeze
- DATE_KEYS =
parsed to Date objects
%w[from_date to_date].freeze
- AMOUNT_KEYS =
kept as strings
%w[min_amount].freeze
Class Method Summary collapse
- .load(pointer_path: CONFIG_POINTER_PATH) ⇒ Object
- .set_config_path(path, pointer_path: CONFIG_POINTER_PATH) ⇒ Object
Class Method Details
.load(pointer_path: CONFIG_POINTER_PATH) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/find_subscriptions/config_loader.rb', line 26 def self.load(pointer_path: CONFIG_POINTER_PATH) return Result.new({}, {}) unless File.exist?(pointer_path) config_path = File.read(pointer_path).strip return Result.new({}, {}) unless File.exist?(config_path) raw = YAML.safe_load_file(config_path) || {} Result.new((raw), raw.fetch('schemas', {})) end |
.set_config_path(path, pointer_path: CONFIG_POINTER_PATH) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/find_subscriptions/config_loader.rb', line 36 def self.set_config_path(path, pointer_path: CONFIG_POINTER_PATH) = File.(path) raise ArgumentError, "Config file not found: #{expanded}" unless File.exist?() File.write(pointer_path, ) puts "Config registered: #{expanded}" end |