Class: Preference
- Inherits:
-
Settingslogic
- Object
- Settingslogic
- Preference
- Defined in:
- app/models/preference.rb
Constant Summary collapse
- BOOLEAN_FIELD_REGEXP =
/(enabled|disabled)/
Class Method Summary collapse
- .admin_preference_names ⇒ Object
- .defaults ⇒ Object
- .general_preference_names ⇒ Object
- .make_toolbox_name_to_preference_names_hash ⇒ Object
- .toolbox_names ⇒ Object
- .toolbox_preference_names ⇒ Object
- .whole_preference_names ⇒ Object
Instance Method Summary collapse
-
#initialize(hash_or_file = self.class.source, section = nil) ⇒ Preference
constructor
A new instance of Preference.
Constructor Details
#initialize(hash_or_file = self.class.source, section = nil) ⇒ Preference
Returns a new instance of Preference.
60 61 62 63 64 65 66 |
# File 'app/models/preference.rb', line 60 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_names ⇒ Object
31 32 33 34 35 |
# File 'app/models/preference.rb', line 31 def self.admin_preference_names %w( enabled_must_signin ) end |
.defaults ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/preference.rb', line 42 def self.defaults (toolbox_preference_names + general_preference_names).map { |n| case n when BOOLEAN_FIELD_REGEXP [n, false] else [n, ""] end }.to_h.merge("toolbox_name" => "default") end |
.general_preference_names ⇒ Object
22 23 24 25 26 27 28 29 |
# 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 hardware_port ) end |
.make_toolbox_name_to_preference_names_hash ⇒ Object
54 55 56 57 58 |
# File 'app/models/preference.rb', line 54 def self.make_toolbox_name_to_preference_names_hash toolbox_preference_names.group_by { |n| n.slice(/^toolbox__(.+?)__/, 1) } end |
.toolbox_names ⇒ Object
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_names ⇒ Object
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_names ⇒ Object
37 38 39 40 |
# File 'app/models/preference.rb', line 37 def self.whole_preference_names ["toolbox_name"] + toolbox_preference_names + general_preference_names + admin_preference_names end |