Class: Decidim::Proposals::Import::ProposalCreator
- Inherits:
-
Admin::Import::Creator
- Object
- Admin::Import::Creator
- Decidim::Proposals::Import::ProposalCreator
- Defined in:
- lib/decidim/proposals/import/proposal_creator.rb
Overview
This class is responsible for creating the imported proposals and must be included in proposals component’s import manifest.
Class Method Summary collapse
-
.resource_klass ⇒ Object
Returns the resource class to be created with the provided data.
-
.verifier_klass ⇒ Object
Returns a verifier class to be used to verify the correctness of the import data.
Instance Method Summary collapse
-
#finish! ⇒ Object
Saves the proposal.
-
#initialize(data, context = nil) ⇒ ProposalCreator
constructor
A new instance of ProposalCreator.
-
#produce ⇒ Object
Produces a proposal from parsed data.
Constructor Details
#initialize(data, context = nil) ⇒ ProposalCreator
Returns a new instance of ProposalCreator.
20 21 22 23 |
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 20 def initialize(data, context = nil) @data = data.except(:id, "id") @context = context end |
Class Method Details
.resource_klass ⇒ Object
Returns the resource class to be created with the provided data.
10 11 12 |
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 10 def self.resource_klass Decidim::Proposals::Proposal end |
.verifier_klass ⇒ Object
Returns a verifier class to be used to verify the correctness of the import data.
16 17 18 |
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 16 def self.verifier_klass Decidim::Proposals::Import::ProposalsVerifier end |
Instance Method Details
#finish! ⇒ Object
Saves the proposal
35 36 37 38 39 40 41 42 |
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 35 def finish! Decidim.traceability.perform_action!(:create, self.class.resource_klass, context[:current_user], visibility: "admin-only") do resource.save! resource end notify(resource) publish(resource) end |
#produce ⇒ Object
Produces a proposal from parsed data
Returns a proposal
28 29 30 31 32 |
# File 'lib/decidim/proposals/import/proposal_creator.rb', line 28 def produce resource.(context[:current_user], user_group: context[:user_group]) resource end |