Class: Maglev::Section::Setting
- Inherits:
-
Object
- Object
- Maglev::Section::Setting
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/maglev/section/setting.rb
Overview
rubocop:disable Style/ClassAndModuleChildren
Constant Summary collapse
- REGISTERED_TYPES =
constants ##
%w[text image checkbox link color select collection_item icon divider hint].freeze
Instance Attribute Summary collapse
-
#default ⇒ Object
attributes ##.
-
#id ⇒ Object
validations ##.
-
#label ⇒ Object
attributes ##.
-
#options ⇒ Object
attributes ##.
-
#type ⇒ Object
attributes ##.
Class Method Summary collapse
-
.build(hash) ⇒ Object
class methods ##.
- .build_many(list) ⇒ Object
- .registered_types ⇒ Object
Instance Method Summary collapse
-
#build_default_content(custom_default = nil) ⇒ Object
NOTE: any modification to that method must be reflected in the JS editor.
- #cast_value(value) ⇒ Object
Instance Attribute Details
#default ⇒ Object
attributes ##
12 13 14 |
# File 'app/models/maglev/section/setting.rb', line 12 def default @default end |
#id ⇒ Object
validations ##
12 13 14 |
# File 'app/models/maglev/section/setting.rb', line 12 def id @id end |
#label ⇒ Object
attributes ##
12 13 14 |
# File 'app/models/maglev/section/setting.rb', line 12 def label @label end |
#options ⇒ Object
attributes ##
12 13 14 |
# File 'app/models/maglev/section/setting.rb', line 12 def @options end |
#type ⇒ Object
attributes ##
12 13 14 |
# File 'app/models/maglev/section/setting.rb', line 12 def type @type end |
Class Method Details
.build(hash) ⇒ Object
class methods ##
42 43 44 45 46 47 |
# File 'app/models/maglev/section/setting.rb', line 42 def self.build(hash) attributes = hash.slice('id', 'label', 'type', 'default') = hash.except('id', 'label', 'type', 'default') new(attributes.merge(options: )) end |
.build_many(list) ⇒ Object
49 50 51 |
# File 'app/models/maglev/section/setting.rb', line 49 def self.build_many(list) list.map { |hash| build(hash) } end |
.registered_types ⇒ Object
53 54 55 56 57 |
# File 'app/models/maglev/section/setting.rb', line 53 def self.registered_types @registered_types ||= REGISTERED_TYPES.index_with do |type| "Maglev::SettingTypes::#{type.camelize}".constantize.new end end |
Instance Method Details
#build_default_content(custom_default = nil) ⇒ Object
NOTE: any modification to that method must be reflected in the JS editor
32 33 34 35 36 37 38 39 |
# File 'app/models/maglev/section/setting.rb', line 32 def build_default_content(custom_default = nil) default = custom_default.nil? ? self.default : custom_default # special case: text type default ||= label if text_type? cast_value(default) end |
#cast_value(value) ⇒ Object
27 28 29 |
# File 'app/models/maglev/section/setting.rb', line 27 def cast_value(value) self.class.registered_types[type.to_s].cast_value(value) end |