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.



76
77
78
79
80
81
82
# File 'app/models/preference.rb', line 76

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_defaultsObject



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

def admin_defaults
  make_defaults(admin_preference_names)
end

.admin_preference_namesObject



32
33
34
35
36
# File 'app/models/preference.rb', line 32

def admin_preference_names
  %w(
    enabled_must_signin
  )
end

.general_preference_namesObject



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

def general_preference_names
  %w(
    disabled_add_character_from_beginning
    disabled_new_character
    enabled_readonly_ruby_mode
    hardware_port
  )
end

.make_toolbox_name_to_preference_names_hashObject



53
54
55
56
57
# File 'app/models/preference.rb', line 53

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

.toolbox_namesObject



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

def toolbox_names
  %w(
    default
    smalrubot_v3
    smalrubot_s1
  )
end

.toolbox_preference_namesObject



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

def toolbox_preference_names
  %w(
    toolbox__default__enabled_hardware_blocks
    toolbox__default__enabled_smalrubot_v3_blocks
    toolbox__default__enabled_smalrubot_s1_blocks
  )
end

.user_defaultsObject



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

def user_defaults
  make_defaults(toolbox_preference_names +
                general_preference_names)
    .merge("toolbox_name" => "default")
end

.whole_preference_namesObject



38
39
40
41
# File 'app/models/preference.rb', line 38

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