Class: Maglev::Section::Block
- Inherits:
-
Object
- Object
- Maglev::Section::Block
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/maglev/section/block.rb
Overview
rubocop:disable Style/ClassAndModuleChildren
Defined Under Namespace
Classes: Store
Instance Attribute Summary collapse
-
#accept ⇒ Object
attributes ##.
-
#limit ⇒ Object
attributes ##.
-
#name ⇒ Object
validation ##.
-
#root ⇒ Object
attributes ##.
-
#section ⇒ Object
attributes ##.
-
#settings ⇒ Object
attributes ##.
-
#type ⇒ Object
attributes ##.
Class Method Summary collapse
-
.build(hash, section:) ⇒ Object
class methods ##.
- .build_many(list, section:) ⇒ Object
Instance Method Summary collapse
- #advanced_settings ⇒ Object
- #as_json ⇒ Object
- #empty? ⇒ Boolean
-
#human_name ⇒ Object
methods.
- #main_settings ⇒ Object
- #root? ⇒ Boolean
Instance Attribute Details
#accept ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/block.rb', line 9 def accept @accept end |
#limit ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/block.rb', line 9 def limit @limit end |
#name ⇒ Object
validation ##
9 10 11 |
# File 'app/models/maglev/section/block.rb', line 9 def name @name end |
#root ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/block.rb', line 9 def root @root end |
#section ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/block.rb', line 9 def section @section end |
#settings ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/block.rb', line 9 def settings @settings end |
#type ⇒ Object
attributes ##
9 10 11 |
# File 'app/models/maglev/section/block.rb', line 9 def type @type end |
Class Method Details
.build(hash, section:) ⇒ Object
class methods ##
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/maglev/section/block.rb', line 43 def self.build(hash, section:) attributes = hash.slice('name', 'type', 'accept', 'root', 'limit') attributes['root'] = true if attributes['root'].nil? attributes['limit'] = -1 if attributes['limit'].nil? new( **attributes.merge( settings: Maglev::Section::Setting.build_many(hash['settings']), section: section ) ) end |
.build_many(list, section:) ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/models/maglev/section/block.rb', line 56 def self.build_many(list, section:) return [] if list.blank? list.map do |hash_or_object| hash_or_object.is_a?(Hash) ? build(hash_or_object, section: section) : hash_or_object end end |
Instance Method Details
#advanced_settings ⇒ Object
29 30 31 |
# File 'app/models/maglev/section/block.rb', line 29 def advanced_settings settings.select(&:advanced?) end |
#as_json ⇒ Object
37 38 39 |
# File 'app/models/maglev/section/block.rb', line 37 def as_json super(only: %i[name type settings root accept]) end |
#empty? ⇒ Boolean
33 34 35 |
# File 'app/models/maglev/section/block.rb', line 33 def empty? settings.none? end |
#human_name ⇒ Object
methods
17 18 19 |
# File 'app/models/maglev/section/block.rb', line 17 def human_name ::I18n.t("#{section.i18n_scope}.blocks.types.#{type}", default: name.humanize) end |
#main_settings ⇒ Object
25 26 27 |
# File 'app/models/maglev/section/block.rb', line 25 def main_settings settings.reject(&:advanced?) end |