Class: Maglev::Content::BlockContent::AssociationProxy

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/models/maglev/content/block_content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(section_content:, raw_blocks_content:) ⇒ AssociationProxy

Returns a new instance of AssociationProxy.



63
64
65
66
67
68
# File 'app/models/maglev/content/block_content.rb', line 63

def initialize(section_content:, raw_blocks_content:)
  @array = Maglev::Content::BlockContent.build_many(
    section_content: section_content,
    raw_blocks_content: raw_blocks_content
  )
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



61
62
63
# File 'app/models/maglev/content/block_content.rb', line 61

def array
  @array
end

Instance Method Details

#can_add?(type) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
# File 'app/models/maglev/content/block_content.rb', line 78

def can_add?(type)
  blocks = find_all_by_type(type)

  return true if blocks.empty?

  definition = blocks.first.definition

  definition.limit == -1 || blocks.size < definition.limit
end

#each(&block) ⇒ Object



88
89
90
# File 'app/models/maglev/content/block_content.rb', line 88

def each(&block)
  array.each(&block)
end

#find(id) ⇒ Object



70
71
72
# File 'app/models/maglev/content/block_content.rb', line 70

def find(id)
  array.find { |block| block.id == id }
end

#find_all_by_type(type) ⇒ Object



74
75
76
# File 'app/models/maglev/content/block_content.rb', line 74

def find_all_by_type(type)
  array.select { |block| block.type == type }
end