Module: RubyCms::ContentBlocksGrouping
- Defined in:
- lib/ruby_cms/content_blocks_grouping.rb
Defined Under Namespace
Classes: Row
Class Method Summary collapse
-
.build_row(key, blocks) ⇒ Object
rubocop:enable Rails/Blank.
-
.group_by_key(collection) ⇒ Object
rubocop:disable Rails/Blank – use plain Ruby for standalone unit specs without Rails.
Class Method Details
.build_row(key, blocks) ⇒ Object
rubocop:enable Rails/Blank
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_cms/content_blocks_grouping.rb', line 27 def build_row(key, blocks) first = blocks.first Row.new( key: key, id: first.id, locale: blocks.map(&:locale).sort.join(", "), title: first.title, content_type: first.content_type, published: blocks.all?(&:published?), content_block: first ) end |
.group_by_key(collection) ⇒ Object
rubocop:disable Rails/Blank – use plain Ruby for standalone unit specs without Rails
17 18 19 20 21 22 23 24 |
# File 'lib/ruby_cms/content_blocks_grouping.rb', line 17 def group_by_key(collection) return [] if collection.nil? || collection.empty? collection .group_by(&:key) .map {|key, blocks| build_row(key, blocks) } .sort_by(&:key) end |