diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-06-12 20:39:48 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-06-13 17:59:13 -0400 |
commit | d2894a39e5b3a8504cb290a2f41b0aac5fc8b0a8 (patch) | |
tree | 12278e2507b6fa301da9b62cf76da3b7e53ebcc8 /app/helpers | |
parent | c0cb77e413fa38625a96323a527ff4dc56d59573 (diff) | |
download | gitlab-ce-d2894a39e5b3a8504cb290a2f41b0aac5fc8b0a8.tar.gz |
Refactor dashboard_choices
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/preferences_helper.rb | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index 6a894186ea6..bceff4fd52e 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -20,22 +20,25 @@ module PreferencesHelper COLOR_SCHEMES.freeze end - # Populates the dashboard preference select field with more user-friendly - # values. - def dashboard_choices - orig = User.dashboards.keys + # Maps `dashboard` values to more user-friendly option text + DASHBOARD_CHOICES = { + projects: 'Your Projects (default)', + stars: 'Starred Projects' + }.with_indifferent_access.freeze - choices = [ - ['Your Projects (default)', orig[0]], - ['Starred Projects', orig[1]] - ] + # Returns an Array usable by a select field for more user-friendly option text + def dashboard_choices + defined = User.dashboards - if orig.size != choices.size - # Assure that anyone adding new options updates this method too - raise RuntimeError, "`User` defines #{orig.size} dashboard choices," + - " but #{__method__} defined #{choices.size}" + if defined.size != DASHBOARD_CHOICES.size + # Ensure that anyone adding new options updates this method too + raise RuntimeError, "`User` defines #{defined.size} dashboard choices," + + " but `DASHBOARD_CHOICES` defined #{DASHBOARD_CHOICES.size}." else - choices + defined.map do |key, _| + # Use `fetch` so `KeyError` gets raised when a key is missing + [DASHBOARD_CHOICES.fetch(key), key] + end end end |