Class: Thredded::MessageboardGroupView

Inherits:
Object
  • Object
show all
Defined in:
app/view_models/thredded/messageboard_group_view.rb

Overview

A view model for a page of MessageboardGroupViews.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, messageboards) ⇒ MessageboardGroupView

Returns a new instance of MessageboardGroupView.

Parameters:



22
23
24
25
# File 'app/view_models/thredded/messageboard_group_view.rb', line 22

def initialize(group, messageboards)
  @group = group
  @messageboards = messageboards
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



7
8
9
# File 'app/view_models/thredded/messageboard_group_view.rb', line 7

def group
  @group
end

#messageboardsObject (readonly)

Returns the value of attribute messageboards.



7
8
9
# File 'app/view_models/thredded/messageboard_group_view.rb', line 7

def messageboards
  @messageboards
end

Class Method Details

.grouped(messageboard_scope) ⇒ Array<MessageboardGroupView>

Parameters:

Returns:



11
12
13
14
15
16
17
18
# File 'app/view_models/thredded/messageboard_group_view.rb', line 11

def self.grouped(messageboard_scope)
  messageboard_scope.preload(last_topic: [:last_user])
    .eager_load(:group)
    .order(Arel.sql('COALESCE(thredded_messageboard_groups.position, 0) ASC, thredded_messageboard_groups.id ASC'))
    .ordered
    .group_by(&:group)
    .map { |(group, messageboards)| MessageboardGroupView.new(group, messageboards) }
end