Class: GitFit::Sync::Base
- Inherits:
-
Object
- Object
- GitFit::Sync::Base
show all
- Defined in:
- lib/git_fit/sync/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config:, db:, activity_filter: nil, privacy: nil, time_budget: nil) ⇒ Base
Returns a new instance of Base.
8
9
10
11
12
13
14
15
16
|
# File 'lib/git_fit/sync/base.rb', line 8
def initialize(config:, db:, activity_filter: nil, privacy: nil, time_budget: nil)
@config = config
@db = db
@activity_filter = activity_filter
@privacy = privacy
@time_budget = time_budget
@start_time = nil
@progress_reported = false
end
|
Instance Attribute Details
#progress_reported ⇒ Object
Returns the value of attribute progress_reported.
18
19
20
|
# File 'lib/git_fit/sync/base.rb', line 18
def progress_reported
@progress_reported
end
|
Class Method Details
.adapters ⇒ Object
86
87
88
|
# File 'lib/git_fit/sync/base.rb', line 86
def adapters
@adapters ||= []
end
|
.config_key(source = nil) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/git_fit/sync/base.rb', line 102
def config_key(source = nil)
if source
@config_key = source
else
@config_key ||= name.split("::").last.downcase
end
end
|
.register_adapter ⇒ Object
94
95
96
|
# File 'lib/git_fit/sync/base.rb', line 94
def register_adapter
Base.adapters << self unless Base.adapters.include?(self)
end
|
.register_config(*keys) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/git_fit/sync/base.rb', line 75
def self.register_config(*keys)
return if keys.empty?
source = config_key
GitFit.register_config_source(
prefix: "GIT_FIT_#{source.upcase}",
keys: keys,
config_path: ["sync", source]
)
end
|
.register_test_adapter ⇒ Object
.test_adapters ⇒ Object
90
91
92
|
# File 'lib/git_fit/sync/base.rb', line 90
def test_adapters
@test_adapters ||= []
end
|
Instance Method Details
#before_call ⇒ Object
36
37
38
39
|
# File 'lib/git_fit/sync/base.rb', line 36
def before_call
@start_time = Time.now
true
end
|
#build_progress_info(attrs) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/git_fit/sync/base.rb', line 49
def build_progress_info(attrs)
parts = []
sd = attrs["start_date"] || attrs[:start_date]
if sd
d = Date.parse(sd.to_s) rescue nil
if d
date_str = d.year == Date.today.year ? d.strftime("%m-%d") : d.strftime("%Y-%m-%d")
parts << date_str
end
end
type = attrs["sport_category"] || attrs[:sport_category]
parts << type if type
dist = attrs["distance"] || attrs[:distance]
if dist && dist.to_f > 0
parts << "#{format("%.1f", dist.to_f / 1000)}km"
end
source = attrs["source"] || attrs[:source] || source_label
name = attrs["name"] || attrs[:name]
display_name = name.to_s.strip
display_name = "#{source} Activity" if display_name.empty?
chars = display_name.chars
display_name = chars.first(30).join + "…" if chars.size > 30
parts << display_name
parts.join(" | ") unless parts.empty?
end
|
#call ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/git_fit/sync/base.rb', line 20
def call
return 0 unless before_call
return 0 unless respond_to?(:authenticate) ? authenticate : true
ids = pending_ids
return 0 if ids.nil? || ids.empty?
total = ids.size
count = 0
ids.filter_map do |p|
next if skip_type?(p[:type])
r = process_one(p)
count += 1
report_progress(count, total, build_progress_info(r)) if r
r
end.size
end
|
#pending_ids ⇒ Object
41
42
43
|
# File 'lib/git_fit/sync/base.rb', line 41
def pending_ids
raise NotImplementedError, "#{self.class} must implement #pending_ids"
end
|
#process_one(pending) ⇒ Object
45
46
47
|
# File 'lib/git_fit/sync/base.rb', line 45
def process_one(pending)
raise NotImplementedError, "#{self.class} must implement #process_one"
end
|