Class: Decidim::Proposals::ProposalSerializer
- Inherits:
-
Object
- Object
- Decidim::Proposals::ProposalSerializer
- Includes:
- ResourceHelper
- Defined in:
- decidim-proposals/app/services/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.
12 13 14 |
# File 'decidim-proposals/app/services/decidim/proposals/proposal_serializer.rb', line 12 def initialize(proposal) @proposal = proposal end |
Instance Method Details
#serialize ⇒ Object
Public: Exports a hash with the serialized data for this proposal.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'decidim-proposals/app/services/decidim/proposals/proposal_serializer.rb', line 17 def serialize { id: @proposal.id, category: { id: @proposal.category.try(:id), name: @proposal.category.try(:name) }, title: @proposal.title, body: @proposal.body, votes: @proposal.proposal_votes_count, comments: @proposal.comments.count, created_at: @proposal.created_at, url: url, feature: { id: feature.id }, meeting_urls: meetings } end |