Class: Collavre::Creatives::CreativeTreeSerializer

Inherits:
Object
  • Object
show all
Defined in:
app/services/collavre/creatives/creative_tree_serializer.rb

Overview

Serializes a flat collection of creatives into the lightweight JSON payload consumed by the picker popup (simple mode) and the plain browse list.

Extracted from CreativesController#index so the controller action stays thin. Depends only on the acting user and the request params (read-only), never on view_context, so the whole responsibility lives outside the controller.

Instance Method Summary collapse

Constructor Details

#initialize(user:, params:) ⇒ CreativeTreeSerializer

Returns a new instance of CreativeTreeSerializer.



10
11
12
13
# File 'app/services/collavre/creatives/creative_tree_serializer.rb', line 10

def initialize(user:, params:)
  @user = user
  @params = params
end

Instance Method Details

#serialize(collection) ⇒ Object



15
16
17
18
19
20
21
# File 'app/services/collavre/creatives/creative_tree_serializer.rb', line 15

def serialize(collection)
  if params[:simple].present?
    serialize_simple(collection)
  else
    collection.map { |c| { id: c.id, description: c.effective_description, progress: c.progress } }
  end
end