Class: Decidim::Admin::UnhideResource

Inherits:
Command
  • Object
show all
Defined in:
decidim-admin/app/commands/decidim/admin/unhide_resource.rb

Overview

A command with all the business logic when a user hides a resource.

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(reportable, current_user) ⇒ UnhideResource

Public: Initializes the command.

reportable - A Decidim::Reportable current_user - the user that performs the action



11
12
13
14
# File 'decidim-admin/app/commands/decidim/admin/unhide_resource.rb', line 11

def initialize(reportable, current_user)
  @reportable = reportable
  @current_user = current_user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid, together with the resource.

  • :invalid if the resource is already hidden

Returns nothing.



22
23
24
25
26
27
# File 'decidim-admin/app/commands/decidim/admin/unhide_resource.rb', line 22

def call
  return broadcast(:invalid) unless unhideable?

  unhide!
  broadcast(:ok, @reportable)
end