git-fit 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e868be2f4295bf56a1af4e653dcadb26bca9c67a3f4cf42e8c5822b55ae380e6
4
- data.tar.gz: 49470e6b69e829a484e7347a44cb48241f9366a6cb2a345023da903e4045d00f
3
+ metadata.gz: 9551667addc842c5ddb8357d32b9d4eb040eedc236eeb3c940f59ea52f8be329
4
+ data.tar.gz: 3ede4c5df18fd6a3380b5aff8845bf2ac1ca7d1074c2507e647e05363bf745fb
5
5
  SHA512:
6
- metadata.gz: d5a45ab91987725f37a00dadf6e16f8c2c45a4258a9bde275bebc8203c12bd7376e9d4605dcd87c1f5432c735c50d9ac30e42deb18b4d92611b1a90418834b7f
7
- data.tar.gz: 2ce6cd5123f4d55ff5f8316c5cdd6c912dc0be3721db63b5a844c149fa38743792a5d2e4c3d46feb3e2d4d23562a7f0c6f04f17d4f9c29728384eb2647f49e07
6
+ metadata.gz: 437969ed9c1dd8ec94de2449cbe8e71e8201bcfe2299fd3dcdcf44c8ae6b4901482b99fdd3459482395896a10c96c455a1acff8c69fd2e242c81e1befdb88941
7
+ data.tar.gz: 11ffe29a5aecb4c305f361c81ad3eef6f73394fc9abb00f75486d68a32caac3de565ef941236120622b63c61059b20486f790e32290ef016da93141266d20b5e
data/lib/git-fit.rb CHANGED
@@ -2,7 +2,21 @@ require "thor"
2
2
  require "yaml"
3
3
  require "fileutils"
4
4
 
5
+ module GitFit
6
+ @registered_configs = []
7
+
8
+ class << self
9
+ attr_reader :registered_configs
10
+
11
+ def register_config_source(prefix:, keys:, config_path:)
12
+ @registered_configs << { prefix: prefix, keys: keys, config_path: config_path }
13
+ end
14
+ end
15
+ end
16
+
5
17
  require_relative "git_fit/version"
6
18
  require_relative "git_fit/config"
7
19
  require_relative "git_fit/config_template"
20
+ require_relative "git_fit/sync/base"
21
+ require_relative "git_fit/sync/strava"
8
22
  require_relative "git_fit/cli"
@@ -59,10 +59,16 @@ module GitFit
59
59
 
60
60
  private
61
61
 
62
- # v0.1.0: 仅支持 DATABASE_PATH 覆盖
63
- # v0.1.1+: 引入 register_config 注册机制
64
62
  def load_env
65
63
  @data["database"]["path"] = ENV["GIT_FIT_DATABASE_PATH"] if ENV["GIT_FIT_DATABASE_PATH"]
64
+
65
+ GitFit.registered_configs.each do |reg|
66
+ reg[:keys].each do |key|
67
+ env_name = "#{reg[:prefix]}_#{key.to_s.upcase}"
68
+ next unless ENV.key?(env_name)
69
+ set_nested(@data, reg[:config_path] + [key.to_s], ENV[env_name])
70
+ end
71
+ end
66
72
  end
67
73
 
68
74
  def validate!
@@ -79,6 +85,23 @@ module GitFit
79
85
  warn "Config: failed to load #{path}: #{e.message}"
80
86
  end
81
87
 
88
+ def set_nested(hash, keys, value)
89
+ last = keys.pop
90
+ keys.each { |k| hash[k] ||= {}; hash = hash[k] }
91
+ hash[last] = typed_value(value)
92
+ end
93
+
94
+ def typed_value(str)
95
+ case str
96
+ when /\A\d+\z/ then str.to_i
97
+ when /\A\d+\.\d+\z/ then str.to_f
98
+ when /\Atrue\z/i then true
99
+ when /\Afalse\z/i then false
100
+ when /\Anil\z/i then nil
101
+ else str
102
+ end
103
+ end
104
+
82
105
  def deep_merge!(target, source)
83
106
  source.each do |key, val|
84
107
  if val.is_a?(Hash) && target[key].is_a?(Hash)
@@ -7,20 +7,20 @@ module GitFit
7
7
  path: db/fit.sqlite3
8
8
 
9
9
  sync:
10
- # strava:
11
- # client_id: ""
12
- # refresh_token: ""
10
+ # strava: # env: GIT_FIT_STRAVA_CLIENT_ID
11
+ # client_id: "" # env: GIT_FIT_STRAVA_CLIENT_SECRET
12
+ # refresh_token: "" # env: GIT_FIT_STRAVA_REFRESH_TOKEN
13
13
 
14
- # garmin:
15
- # email: ""
14
+ # garmin: # env: GIT_FIT_GARMIN_EMAIL
15
+ # email: "" # env: GIT_FIT_GARMIN_PASSWORD
16
16
  # password: ""
17
17
 
18
- # keep:
19
- # phone: ""
18
+ # keep: # env: GIT_FIT_KEEP_PHONE
19
+ # phone: "" # env: GIT_FIT_KEEP_PASSWORD
20
20
  # password: ""
21
21
 
22
- # igpsport:
23
- # phone: ""
22
+ # igpsport: # env: GIT_FIT_IGPSPORT_PHONE
23
+ # phone: "" # env: GIT_FIT_IGPSPORT_PASSWORD
24
24
  # password: ""
25
25
 
26
26
  export:
@@ -0,0 +1,16 @@
1
+ module GitFit
2
+ module Sync
3
+ class Base
4
+ def self.register_config(*keys)
5
+ return if keys.empty?
6
+
7
+ source = name.split("::").last.downcase
8
+ GitFit.register_config_source(
9
+ prefix: "GIT_FIT_#{source.upcase}",
10
+ keys: keys,
11
+ config_path: ["sync", source]
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module GitFit
2
+ module Sync
3
+ class Strava < Base
4
+ register_config :client_id, :client_secret, :refresh_token
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module GitFit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-fit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax
@@ -37,6 +37,8 @@ files:
37
37
  - lib/git_fit/cli.rb
38
38
  - lib/git_fit/config.rb
39
39
  - lib/git_fit/config_template.rb
40
+ - lib/git_fit/sync/base.rb
41
+ - lib/git_fit/sync/strava.rb
40
42
  - lib/git_fit/version.rb
41
43
  homepage: https://github.com/Lax/git-fit
42
44
  licenses: