Class: Decidim::TimeTracker::StopLastTimeEvent

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/time_tracker/stop_last_time_event.rb

Overview

Stops the last event for the user

Instance Attribute Summary collapse

Instance Method Summary collapse

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_userObject (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

#formObject (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

#callObject

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.message)
  end

  broadcast(:ok, @last_entry)
end