Class: Rosette::Core::BranchUtils
- Inherits:
-
Object
- Object
- Rosette::Core::BranchUtils
- Defined in:
- lib/rosette/core/branch_utils.rb
Overview
Utility methods that work at the branch level.
Class Method Summary collapse
- .derive_branch_name(commit_id, repo) ⇒ Object
-
.derive_locale_statuses_from(commit_logs, repo_name, datastore, phrase_count = nil) ⇒ Hash
Computes the status for each individual locale contained in the given list of commit logs.
-
.derive_phrase_count_from(commit_logs) ⇒ Fixnum
Computes the phrase count for the given list of commit logs.
-
.derive_status_from(commit_logs) ⇒ PhraseStatus
Computes the status for an array of commit logs.
-
.fill_in_missing_locales(all_locales, locale_statuses) ⇒ Hash
Adds any missing locale keys to a hash of locale statuses.
Class Method Details
.derive_branch_name(commit_id, repo) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/rosette/core/branch_utils.rb', line 106 def derive_branch_name(commit_id, repo) refs = repo.refs_containing(commit_id).map(&:getName) if refs.include?('refs/remotes/origin/master') 'refs/remotes/origin/master' else filter_refs(refs).first end end |
.derive_locale_statuses_from(commit_logs, repo_name, datastore, phrase_count = nil) ⇒ Hash
Computes the status for each individual locale contained in the given list of commit logs. Locale statuses are hashes that contain a count of the number of translated phrases for that locale as well as the percent translated.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rosette/core/branch_utils.rb', line 63 def derive_locale_statuses_from(commit_logs, repo_name, datastore, phrase_count = nil) phrase_count ||= derive_phrase_count_from(commit_logs) locale_statuses = commit_logs.each_with_object({}) do |commit_log, ret| locale_entries = datastore.commit_log_locales_for( repo_name, commit_log.commit_id ) locale_entries.each do |locale_entry| ret[locale_entry.locale] ||= { translated_count: 0 } ret[locale_entry.locale].tap do |locale_hash| locale_hash[:translated_count] += locale_entry.translated_count end end end add_translation_percentages(locale_statuses, phrase_count) end |
.derive_phrase_count_from(commit_logs) ⇒ Fixnum
Computes the phrase count for the given list of commit logs. This is simply the sum of all the commit log’s phrase counts.
43 44 45 |
# File 'lib/rosette/core/branch_utils.rb', line 43 def derive_phrase_count_from(commit_logs) commit_logs.inject(0) { |sum, entry| sum + entry.phrase_count } end |
.derive_status_from(commit_logs) ⇒ PhraseStatus
Computes the status for an array of commit logs. Determining the aggregate status of more than one commit log means choosing the least far-along status from the list. In other words, if the list contains two commit logs with FETCHED and FINALIZED statuses respectively, this method will return FETCHED because that’s the least advanced status in the list. A list of commit logs is only as advanced as its ‘weakest’, least advanced element.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rosette/core/branch_utils.rb', line 23 def derive_status_from(commit_logs) ps = Rosette::DataStores::PhraseStatus entry = commit_logs.min_by { |entry| ps.index(entry.status) } if entry entry.status else # since FINALIZED commit_logs aren't considered, the absence of any # commit logs (i.e. a nil entry) indicates the branch is fully # processed Rosette::DataStores::PhraseStatus::FINALIZED end end |
.fill_in_missing_locales(all_locales, locale_statuses) ⇒ Hash
Adds any missing locale keys to a hash of locale statuses.
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rosette/core/branch_utils.rb', line 93 def fill_in_missing_locales(all_locales, locale_statuses) all_locales.each_with_object({}) do |locale, ret| if found_locale_status = locale_statuses[locale.code] ret[locale.code] = found_locale_status else ret[locale.code] = { percent_translated: 0.0, translated_count: 0 } end end end |