Passed
Push — master ( 6bc43d...2da2ee )
by Ahmad
07:04
created

Setting   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 45
rs 10
c 1
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A update_value() 0 5 1
B default_value() 0 17 7
A get_value() 0 13 1
1
# frozen_string_literal: true
2
3
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
#
5
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
6
#
7
# This program is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU Lesser General Public License as published by the Free Software
9
# Foundation; either version 3.0 of the License, or (at your option) any later
10
# version.
11
#
12
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
#
16
# You should have received a copy of the GNU Lesser General Public License along
17
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
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
    # Return feature value if already exists
32
    features.each do |feature|
33
      next if feature.name != name
34
35
      return feature.value if feature.enabled
36
      return default_value(name)
37
    end
38
39
    # Create the feature since it doesn't exist
40
    features.create(name: name)
41
    default_value(name)
42
  end
43
44
  private
45
46
  def default_value(name)
47
    # return default value
48
    case name
49
    when "Branding Image"
50
      Rails.configuration.branding_image_default
51
    when "Primary Color"
52
      Rails.configuration.primary_color_default
53
    when "Registration Method"
54
      Rails.configuration.registration_method_default
55
    when "Room Authentication"
56
      false
57
    when "Room Limit"
58
      Rails.configuration.number_of_rooms_default
59
    when "Shared Access"
60
      Rails.configuration.shared_access_default
61
    end
62
  end
63
end
64