Class: Decidim::TimeTracker::StopLastTimeEvent
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::TimeTracker::StopLastTimeEvent
- Defined in:
- app/commands/decidim/time_tracker/stop_last_time_event.rb
Overview
Stops the last event for the user
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(current_user) ⇒ StopLastTimeEvent
constructor
Public: Initializes the command.
Constructor Details
#initialize(current_user) ⇒ StopLastTimeEvent
Public: Initializes the command.
form - A form object with the params.
10 11 12 |
# File 'app/commands/decidim/time_tracker/stop_last_time_event.rb', line 10 def initialize(current_user) @current_user = current_user end |
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
32 33 34 |
# File 'app/commands/decidim/time_tracker/stop_last_time_event.rb', line 32 def current_user @current_user end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
32 33 34 |
# File 'app/commands/decidim/time_tracker/stop_last_time_event.rb', line 32 def form @form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the form wasn’t valid and we couldn’t proceed.
Returns nothing.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/commands/decidim/time_tracker/stop_last_time_event.rb', line 20 def call return broadcast(:already_stopped, @last_entry) if last_entry.stopped? begin stop_time_event! rescue StandardError => e return broadcast(:invalid, e.) end broadcast(:ok, @last_entry) end |