-
-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathsync_concept.rb
More file actions
69 lines (53 loc) · 1.95 KB
/
sync_concept.rb
File metadata and controls
69 lines (53 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Git::SyncConcept < Git::Sync
include Mandate
def initialize(concept, force_sync: false)
super(concept.track, concept.synced_to_git_sha)
@concept = concept
@force_sync = force_sync
end
def call
return concept.update_columns(synced_to_git_sha: head_git_concept.synced_git_sha) unless force_sync || concept_needs_updating?
concept.update!(
slug: concept_config[:slug],
name: concept_config[:name],
blurb: head_git_concept.blurb,
synced_to_git_sha: head_git_concept.synced_git_sha
)
Git::SyncConceptAuthors.(concept)
Git::SyncConceptContributors.(concept)
localize!(:concept_name, concept.name)
localize!(:concept_blurb, concept.blurb)
localize!(:concept_introduction, concept.introduction)
localize!(:concept_about, concept.about)
end
private
attr_reader :concept, :force_sync
def localize!(type, content)
return unless content.present?
Localization::Text::AddToLocalization.defer(type, content, concept.id)
end
def concept_needs_updating?
track_config_concept_modified? || concept_config_modified?
end
def track_config_concept_modified?
return false unless track_config_modified?
concept_config[:slug] != concept.slug ||
concept_config[:name] != concept.name ||
head_git_concept.blurb != concept.blurb
end
def concept_config_modified?
return false unless filepath_in_diff?(head_git_concept.config_absolute_filepath)
head_git_concept.blurb != concept.blurb ||
head_git_concept.authors.to_a.sort != concept.authors.map(&:github_username).sort ||
head_git_concept.contributors.to_a.sort != concept.contributors.map(&:github_username).sort
end
memoize
def concept_config
# TODO: (Optional) determine what to do when the concept could not be found
head_git_track.find_concept(concept.uuid)
end
memoize
def head_git_concept
Git::Concept.new(concept_config[:slug], git_repo.head_sha, repo: git_repo)
end
end