Total Complexity | 5 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | # frozen_string_literal: true |
||
19 | class Setting < ApplicationRecord |
||
20 | has_many :features |
||
21 | |||
22 | # Updates the value of the feature and enables it |
||
23 | def update_value(name, value) |
||
24 | feature = features.find_or_create_by!(name: name) |
||
25 | |||
26 | feature.update_attributes(value: value, enabled: true) |
||
27 | end |
||
28 | |||
29 | # Returns the value if enabled or the default if not enabled |
||
30 | def get_value(name) |
||
31 | feature = features.find_or_create_by!(name: name) |
||
32 | if feature[:enabled] |
||
33 | feature[:value] |
||
34 | else |
||
35 | case name |
||
36 | when "Branding Image" |
||
37 | Rails.configuration.branding_image_default |
||
38 | when "Primary Color" |
||
39 | Rails.configuration.primary_color_default |
||
40 | end |
||
41 | end |
||
42 | end |
||
43 | end |
||
44 |