Sha256: 3e182c14d4d17bd5b305c01032711e67e1ef5a72599c125784511a25cd4a0362

Contents?: true

Size: 900 Bytes

Versions: 25

Compression:

Stored size: 900 Bytes

Contents

# frozen_string_literal: true

# rubocop:disable Style/ClassAndModuleChildren
class Maglev::Section::Block
  ## concerns ##
  include ActiveModel::Model

  ## attributes ##
  attr_accessor :name, :type, :settings, :root, :accept, :limit

  ## validation ##
  validates :name, :type, presence: true
  validates :settings, 'maglev/collection': true

  ## methods

  def root?
    !!root
  end

  ## class methods ##

  def self.build(hash)
    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'])
      )
    )
  end

  def self.build_many(list)
    return [] if list.blank?

    list.map { |hash| build(hash) }
  end
end
# rubocop:enable Style/ClassAndModuleChildren

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
maglevcms-1.8.0 app/models/maglev/section/block.rb
maglevcms-1.7.3 app/models/maglev/section/block.rb
maglevcms-1.7.2 app/models/maglev/section/block.rb
maglevcms-1.7.1 app/models/maglev/section/block.rb
maglevcms-1.7.0 app/models/maglev/section/block.rb
maglevcms-1.6.1 app/models/maglev/section/block.rb
maglevcms-1.6.0 app/models/maglev/section/block.rb
maglevcms-1.5.1 app/models/maglev/section/block.rb
maglevcms-1.4.0 app/models/maglev/section/block.rb
maglevcms-1.3.0 app/models/maglev/section/block.rb
maglevcms-1.2.2 app/models/maglev/section/block.rb
maglevcms-1.2.1 app/models/maglev/section/block.rb
maglevcms-1.2.0 app/models/maglev/section/block.rb
maglevcms-1.1.7 app/models/maglev/section/block.rb
maglevcms-1.1.6 app/models/maglev/section/block.rb
maglevcms-1.1.5 app/models/maglev/section/block.rb
maglevcms-1.1.4 app/models/maglev/section/block.rb
maglevcms-1.1.3 app/models/maglev/section/block.rb
maglevcms-1.1.2 app/models/maglev/section/block.rb
maglevcms-1.1.1 app/models/maglev/section/block.rb