Class: Maglev::Content::BlockContent::AssociationProxy
- Inherits:
-
Object
- Object
- Maglev::Content::BlockContent::AssociationProxy
- Includes:
- Enumerable
- Defined in:
- app/models/maglev/content/block_content.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
readonly
Returns the value of attribute array.
Instance Method Summary collapse
- #can_add?(type) ⇒ Boolean
- #each(&block) ⇒ Object
- #find(id) ⇒ Object
- #find_all_by_type(type) ⇒ Object
-
#initialize(section_content:, raw_blocks_content:) ⇒ AssociationProxy
constructor
A new instance of AssociationProxy.
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
#array ⇒ Object (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
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 |