Class: Decidim::EndorseResource
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::EndorseResource
- Defined in:
- app/commands/decidim/endorse_resource.rb
Overview
A command with all the business logic related with a user endorsing a resource. This is a user creates and endorsement.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(resource, current_user, current_group_id = nil) ⇒ EndorseResource
constructor
Public: Initializes the command.
Constructor Details
#initialize(resource, current_user, current_group_id = nil) ⇒ EndorseResource
Public: Initializes the command.
resource - An instance of Decidim::Endorsable. current_user - The current user. current_group_id- (optional) The current_grup that is endorsing the Resource.
12 13 14 15 16 |
# File 'app/commands/decidim/endorse_resource.rb', line 12 def initialize(resource, current_user, current_group_id = nil) @resource = resource @current_user = current_user @current_group_id = current_group_id end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid, together with the resource vote.
-
:invalid if the form wasn’t valid and we couldn’t proceed.
Returns nothing.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/commands/decidim/endorse_resource.rb', line 24 def call return broadcast(:invalid) if existing_group_endorsement? endorsement = build_resource_endorsement if endorsement.save notify_endorser_followers broadcast(:ok, endorsement) else broadcast(:invalid) end end |