Class: Decidim::TimeTracker::StartTimeEvent
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::TimeTracker::StartTimeEvent
- Defined in:
- app/commands/decidim/time_tracker/start_time_event.rb
Overview
A command with all the business logic when creating a time event
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ StartTimeEvent
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ StartTimeEvent
Public: Initializes the command.
form - A form object with the params.
10 11 12 |
# File 'app/commands/decidim/time_tracker/start_time_event.rb', line 10 def initialize(form) @form = form end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
38 39 40 |
# File 'app/commands/decidim/time_tracker/start_time_event.rb', line 38 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 31 32 33 34 35 36 |
# File 'app/commands/decidim/time_tracker/start_time_event.rb', line 20 def call return broadcast(:invalid, form.errors&.first&.second) if form.invalid? return broadcast(:already_active, @time_entry) if already_active? return broadcast(:invalid, form.errors&.first&.second) if activity_invalid? begin stop_previous_activity create_time_event! StopCounterJob.set(wait: form.activity.remaining_seconds_for_today.seconds).perform_later(@time_entry) rescue StandardError => e return broadcast(:invalid, e.) end broadcast(:ok, @time_entry) end |