Class: ReferenceEvent
Defined Under Namespace
Modules: Levels, Slugs
Constant Summary
collapse
- DISPATCHABLE_EVENTS =
as an example for dispatchable events, use invalid employee only create event for invoices which pass to new status which don’t have events
[
Slugs::INVALID_EMPLOYEE,
Slugs::EMPLOYEES_WITHOUT_TIMESHEETS,
Slugs::PAYROLL_PERIOD_WITHOUT_TRANSACTION,
Slugs::UNREVIEWED_PAYROLL_TRANSACTION,
Slugs::NEW_LOAD_TENDER,
Slugs::INVOICE_SENT_VIA_EDI,
Slugs::INVALID_INVOICE
].freeze
- PROCESSABLE_EVENTS =
as an example for processable events, use invoice sent via edi
[
Slugs::EMPLOYEE_PAYROLL_DISBURSEMENT,
Slugs::INVOICE_SENT_VIA_EDI
].freeze
- VALID_LEVELS =
[
Levels::DEBUG,
Levels::INFO,
Levels::WARN,
Levels::ERROR,
Levels::FATAL,
Levels::UNKNOWN
].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection
Instance Method Details
#description ⇒ Object
156
157
158
|
# File 'app/models/reference_event.rb', line 156
def description
I18n.t("reference_events.#{slug.underscore}.description")
end
|
#end_event! ⇒ Object
135
136
137
138
139
|
# File 'app/models/reference_event.rb', line 135
def end_event!
update!(
end_at: Time.current
)
end
|
#error? ⇒ Boolean
123
124
125
|
# File 'app/models/reference_event.rb', line 123
def error?
[Levels::ERROR, Levels::FATAL].include?(level)
end
|
#event_notification_configuration ⇒ Object
106
107
108
109
110
111
|
# File 'app/models/reference_event.rb', line 106
def event_notification_configuration
EventNotificationConfiguration.find_by(
event_slug: slug,
company_id: company_id
)
end
|
#event_notification_configuration_id ⇒ Object
145
146
147
148
149
150
|
# File 'app/models/reference_event.rb', line 145
def event_notification_configuration_id
@event_notification_configuration_id ||= EventNotificationConfiguration.find_by(
event_slug: slug,
company_id: company_id
).id
end
|
#event_notification_deliveries(company_id:) ⇒ Object
113
114
115
116
117
118
119
120
121
|
# File 'app/models/reference_event.rb', line 113
def event_notification_deliveries(company_id:)
EventNotificationDelivery.joins(:event_notification_configuration)
.where(
event_notification_configurations: {
event_slug: slug,
company_id: company_id
}
)
end
|
141
142
143
|
# File 'app/models/reference_event.rb', line 141
def formatted_created_date
I18n.l(created_at, format: :long_with_time)
end
|
#last_deliveries(limit: 10) ⇒ Object
168
169
170
171
172
173
174
175
176
177
|
# File 'app/models/reference_event.rb', line 168
def last_deliveries(limit: 10)
event_notification_deliveries(company_id: company_id)
.order(delivered_at: :desc)
.limit(limit)
.as_json(
methods: [
:recipient_email
]
)
end
|
#name ⇒ Object
152
153
154
|
# File 'app/models/reference_event.rb', line 152
def name
I18n.t("reference_events.#{slug.underscore}.name")
end
|
#occurence_description ⇒ Object
160
161
162
163
164
165
166
|
# File 'app/models/reference_event.rb', line 160
def occurence_description
I18n.t(
"reference_events.#{slug.underscore}.occurence_description",
**reference_attributes,
created_at: formatted_created_date
)
end
|
#process ⇒ Object
187
188
189
|
# File 'app/models/reference_event.rb', line 187
def process
processor_class.new(reference_event: self).process
end
|
#reference_name ⇒ Object
183
184
185
|
# File 'app/models/reference_event.rb', line 183
def reference_name
reference.name
end
|
#reference_url ⇒ Object
179
180
181
|
# File 'app/models/reference_event.rb', line 179
def reference_url
reference.url
end
|
#status ⇒ Object
127
128
129
|
# File 'app/models/reference_event.rb', line 127
def status
end_at ? 'ended' : 'active'
end
|
#update_event ⇒ Object
131
132
133
|
# File 'app/models/reference_event.rb', line 131
def update_event
updater_class.new(reference_event: self).updated_event
end
|