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
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
Instance Method Summary collapse
- #build_default_checkbox_content(default) ⇒ Object
- #build_default_collection_item_content(default) ⇒ Object
-
#build_default_content(custom_default = nil) ⇒ Object
NOTE: any modification to that method must be reflected to the JS editor.
- #build_default_image_content(default) ⇒ Object
- #build_default_link_content(default) ⇒ Object
Instance Attribute Details
#default ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/setting.rb', line 9 def default @default end |
#id ⇒ Object
validations ##
9 10 11 |
# File 'app/models/maglev/section/setting.rb', line 9 def id @id end |
#label ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/setting.rb', line 9 def label @label end |
#options ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/setting.rb', line 9 def @options end |
#type ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/setting.rb', line 9 def type @type end |
Class Method Details
.build(hash) ⇒ Object
class methods ##
51 52 53 54 55 56 |
# File 'app/models/maglev/section/setting.rb', line 51 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
58 59 60 |
# File 'app/models/maglev/section/setting.rb', line 58 def self.build_many(list) list.map { |hash| build(hash) } end |
Instance Method Details
#build_default_checkbox_content(default) ⇒ Object
42 43 44 |
# File 'app/models/maglev/section/setting.rb', line 42 def build_default_checkbox_content(default) default.presence || false end |
#build_default_collection_item_content(default) ⇒ Object
46 47 48 |
# File 'app/models/maglev/section/setting.rb', line 46 def build_default_collection_item_content(default) { id: default } end |
#build_default_content(custom_default = nil) ⇒ Object
NOTE: any modification to that method must be reflected to the JS editor
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/maglev/section/setting.rb', line 18 def build_default_content(custom_default = nil) default = custom_default.nil? ? self.default : custom_default case type.to_sym when :image then build_default_image_content(default) when :link then build_default_link_content(default) when :checkbox then build_default_checkbox_content(default) when :collection_item then build_default_collection_item_content(default) else default || label end end |
#build_default_image_content(default) ⇒ Object
30 31 32 |
# File 'app/models/maglev/section/setting.rb', line 30 def build_default_image_content(default) default.is_a?(String) ? { url: default } : default || {} end |
#build_default_link_content(default) ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/maglev/section/setting.rb', line 34 def build_default_link_content(default) if default.is_a?(String) { text: 'Link', link_type: 'url', href: default } else { text: 'Link', link_type: 'url', href: '#' }.merge(default) end end |