Class: Decidim::Proposals::ProposalSerializer
- Inherits:
-
Exporters::Serializer
- Object
- Exporters::Serializer
- Decidim::Proposals::ProposalSerializer
- Includes:
- ApplicationHelper, ResourceHelper, TranslationsHelper
- Defined in:
- lib/decidim/proposals/proposal_serializer.rb
Overview
This class serializes a Proposal so can be exported to CSV, JSON or other formats.
Instance Method Summary collapse
-
#initialize(proposal) ⇒ ProposalSerializer
constructor
Public: Initializes the serializer with a proposal.
-
#serialize ⇒ Object
Public: Exports a hash with the serialized data for this proposal.
Constructor Details
#initialize(proposal) ⇒ ProposalSerializer
Public: Initializes the serializer with a proposal.
13 14 15 |
# File 'lib/decidim/proposals/proposal_serializer.rb', line 13 def initialize(proposal) @proposal = proposal end |
Instance Method Details
#serialize ⇒ Object
Public: Exports a hash with the serialized data for this proposal.
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 46 47 48 |
# File 'lib/decidim/proposals/proposal_serializer.rb', line 18 def serialize { id: proposal.id, category: { id: proposal.category.try(:id), name: proposal.category.try(:name) || empty_translatable }, scope: { id: proposal.scope.try(:id), name: proposal.scope.try(:name) || empty_translatable }, participatory_space: { id: proposal.participatory_space.id, url: Decidim::ResourceLocatorPresenter.new(proposal.participatory_space).url }, component: { id: component.id }, title: present(proposal).title, body: present(proposal).body, state: proposal.state.to_s, reference: proposal.reference, supports: proposal.proposal_votes_count, endorsements: proposal.endorsements.count, comments: proposal.comments.count, attachments: proposal..count, followers: proposal.followers.count, published_at: proposal.published_at, url: url, meeting_urls: meetings, related_proposals: } end |