Class: GitFit::Config
- Inherits:
-
Object
- Object
- GitFit::Config
- Defined in:
- lib/git_fit/config.rb
Overview
三优先级: env var > YAML > DEFAULTS
Constant Summary collapse
- DEFAULTS =
{ "database" => { "path" => "db/fit.sqlite3" }, "sync" => {}, "export" => { "json" => { "path" => "site/activities.json" }, "svg" => { "dir" => "site/svg" }, "csv" => { "path" => "site/workouts.csv" }, "gpx" => { "path" => "site/gpx_out" } }, "privacy" => { "start_end_range" => 200 }, "system" => { "units" => "metric", "log_level" => "info", "timezone" => "Asia/Shanghai" } }.freeze
- DEFAULT_PATH =
"config/config.yml"- KNOWN_TOP_KEYS =
%w[database sync export privacy system].freeze
Instance Method Summary collapse
- #[](key) ⇒ Object
- #db_path ⇒ Object
- #dig(*keys) ⇒ Object
- #export_config ⇒ Object
-
#initialize(path = nil) ⇒ Config
constructor
A new instance of Config.
- #privacy_config ⇒ Object
- #sync_config(source) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ Config
Returns a new instance of Config.
28 29 30 31 32 33 34 |
# File 'lib/git_fit/config.rb', line 28 def initialize(path = nil) @data = deep_dup(DEFAULTS) load_file(path) if path load_file(DEFAULT_PATH) if !path && File.exist?(DEFAULT_PATH) load_env validate! end |
Instance Method Details
#[](key) ⇒ Object
36 37 38 |
# File 'lib/git_fit/config.rb', line 36 def [](key) @data[key] end |
#db_path ⇒ Object
56 57 58 |
# File 'lib/git_fit/config.rb', line 56 def db_path @data.dig("database", "path") || DEFAULTS["database"]["path"] end |
#dig(*keys) ⇒ Object
40 41 42 |
# File 'lib/git_fit/config.rb', line 40 def dig(*keys) @data.dig(*keys) end |
#export_config ⇒ Object
52 53 54 |
# File 'lib/git_fit/config.rb', line 52 def export_config @data["export"] || {} end |
#privacy_config ⇒ Object
48 49 50 |
# File 'lib/git_fit/config.rb', line 48 def privacy_config @data["privacy"] || {} end |
#sync_config(source) ⇒ Object
44 45 46 |
# File 'lib/git_fit/config.rb', line 44 def sync_config(source) @data.dig("sync", source) || {} end |