Class: EventFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/event_factory.rb

Overview

rubocop:todo Style/Documentation

Class Method Summary collapse

Class Method Details

.new_project(project, user) ⇒ Object

Creates an event when a new project is created This used to send a notification using EventfulMailer, but it is no longer required


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/event_factory.rb', line 10

def self.new_project(project, user)
  content = "Project registered by #{user.}"

  event =
    Event.new(
      eventful_id: project.id,
      eventful_type: 'Project',
      message: 'Project registered',
      created_by: user.,
      content: content,
      of_interest_to: 'administrators'
    )
  event.save
end

.project_approved(project, user) ⇒ Object

Creates an event or emails when a project is approved This used to send a notification using EventfulMailer, but it is no longer required


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/event_factory.rb', line 27

def self.project_approved(project, user)
  content = "Project approved by #{user.}"

  event =
    Event.new(
      eventful_id: project.id,
      eventful_type: 'Project',
      message: 'Project approved',
      created_by: user.,
      content: content,
      of_interest_to: 'administrators'
    )
  event.save
end

.project_refund_request(project, user, reference) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/event_factory.rb', line 42

def self.project_refund_request(project, user, reference)
  content = "Refund request by #{user.}. Reference #{reference}"

  event =
    Event.new(
      eventful_id: project.id,
      eventful_type: 'Project',
      message: "Refund #{reference}",
      created_by: user.,
      content: content,
      of_interest_to: 'administrators'
    )
  event.save
end

.request_update_note_to_manager(request, user, message) ⇒ Object

creates an event and sends an email when update(s) to a request fail rubocop:todo Metrics/MethodLength


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/event_factory.rb', line 63

def self.request_update_note_to_manager(request, user, message) # rubocop:todo Metrics/AbcSize
  content =
    # rubocop:todo Layout/LineLength
    "#{message}\nwhilst an attempt was made to update request #{request.id}\nby user '#{user.}' on #{Time.zone.now}"

  # rubocop:enable Layout/LineLength

  request_event =
    Event.create(
      eventful_id: request.id,
      eventful_type: 'Request',
      message: 'Request update(s) failed',
      created_by: user.,
      content: content,
      of_interest_to: 'manager'
    )

  recipients = []
  request.initial_project.tap { |project| recipients << project.manager.email if project && project.manager }

  EventfulMailer.confirm_event(
    recipients.reject(&:blank?),
    request_event.eventful,
    request_event.message,
    request_event.content,
    'No Milestone'
  ).deliver_now
end