Class: Decidim::Budgets::ProjectSerializer

Inherits:
Exporters::Serializer
  • Object
show all
Includes:
ApplicationHelper, ResourceHelper, TranslationsHelper
Defined in:
lib/decidim/budgets/project_serializer.rb

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ ProjectSerializer

Public: Initializes the serializer with a project.



11
12
13
# File 'lib/decidim/budgets/project_serializer.rb', line 11

def initialize(project)
  @project = project
end

Instance Method Details

#serializeObject

Public: Exports a hash with the serialized data for this project.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/decidim/budgets/project_serializer.rb', line 16

def serialize
  {
    id: project.id,
    category: {
      id: project.category.try(:id),
      name: project.category.try(:name) || empty_translatable
    },
    scope: {
      id: project.scope.try(:id),
      name: project.scope.try(:name) || empty_translatable
    },
    participatory_space: {
      id: project.participatory_space.id,
      url: Decidim::ResourceLocatorPresenter.new(project.participatory_space).url
    },
    component: { id: component.id },
    title: project.title,
    description: project.description,
    budget: { id: project.budget.id },
    budget_amount: project.budget_amount,
    confirmed_votes: project.confirmed_orders_count,
    comments: project.comments_count,
    created_at: project.created_at,
    url: project.polymorphic_resource_url({}),
    address: project.address,
    related_proposals:,
    related_proposal_titles:,
    related_proposal_urls:
  }
end