Class: Preference

Inherits:
Settingslogic
  • Object
show all
Defined in:
app/models/preference.rb

Constant Summary collapse

BOOLEAN_FIELD_REGEXP =
/(enabled|disabled)/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_file = self.class.source, section = nil) ⇒ Preference

Returns a new instance of Preference.



54
55
56
57
58
59
60
# File 'app/models/preference.rb', line 54

def initialize(hash_or_file = self.class.source, section = nil)
  super
rescue NoMethodError
  replace({})
  @section = section || self.class.source
  create_accessors!
end

Class Method Details

.admin_preference_namesObject



30
31
32
33
34
# File 'app/models/preference.rb', line 30

def self.admin_preference_names
  %w(
    enabled_must_signin
  )
end

.defaultsObject



41
42
43
44
45
46
# File 'app/models/preference.rb', line 41

def self.defaults
  (toolbox_preference_names +
   general_preference_names).map { |n|
    [n, false]
  }.to_h.merge("toolbox_name" => "default")
end

.general_preference_namesObject



22
23
24
25
26
27
28
# File 'app/models/preference.rb', line 22

def self.general_preference_names
  %w(
    disabled_add_character_from_beginning
    disabled_new_character
    enabled_readonly_ruby_mode
  )
end

.make_toolbox_name_to_preference_names_hashObject



48
49
50
51
52
# File 'app/models/preference.rb', line 48

def self.make_toolbox_name_to_preference_names_hash
  toolbox_preference_names.group_by { |n|
    n.slice(/^toolbox__(.+?)__/, 1)
  }
end

.toolbox_namesObject



6
7
8
9
10
11
12
# File 'app/models/preference.rb', line 6

def self.toolbox_names
  %w(
    default
    smalrubot_v3
    smalrubot_s1
  )
end

.toolbox_preference_namesObject



14
15
16
17
18
19
20
# File 'app/models/preference.rb', line 14

def self.toolbox_preference_names
  %w(
    toolbox__default__enabled_hardware_blocks
    toolbox__default__enabled_smalrubot_v3_blocks
    toolbox__default__enabled_smalrubot_s1_blocks
  )
end

.whole_preference_namesObject



36
37
38
39
# File 'app/models/preference.rb', line 36

def self.whole_preference_names
  ["toolbox_name"] + toolbox_preference_names +
    general_preference_names + admin_preference_names
end