Class: Ddr::Events::Event
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ddr::Events::Event
- Defined in:
- lib/ddr/events/event.rb
Direct Known Subclasses
CreationEvent, DeletionEvent, FixityCheckEvent, IngestionEvent, MigrationEvent, ReplicationEvent, UpdateEvent, ValidationEvent, VirusCheckEvent
Constant Summary collapse
- DATE_TIME_FORMAT =
Event date time - for PREMIS and Solr
"%Y-%m-%dT%H:%M:%S.%LZ"
- DEFAULT_SORT_ORDER =
set default ordering
"event_date_time ASC"
- SUCCESS =
Outcomes
"success"
- FAILURE =
"failure"
- OUTCOMES =
[SUCCESS, FAILURE]
- VALID =
Validation constants
"VALID"
- INVALID =
"INVALID"
- SYSTEM =
For rendering “performed by” when no associated user
"SYSTEM"
- DDR_SOFTWARE =
"ddr-models #{Ddr::Models::VERSION}"
Class Method Summary collapse
-
.call(*args) ⇒ Object
Receive message sent by ActiveSupport::Notifications.
-
.for_object(obj) ⇒ Object
Scopes.
- .for_pid(pid) ⇒ Object
Instance Method Summary collapse
- #comment_or_summary ⇒ Object
-
#display_type ⇒ Object
Rendering methods.
-
#event_date_time_s ⇒ Object
Return a date/time formatted as a string suitable for use as a PREMIS eventDateTime.
- #failure! ⇒ Object
- #failure? ⇒ Boolean
-
#object ⇒ Object
Object getter and setter.
- #object=(obj) ⇒ Object
- #performed_by ⇒ Object
-
#pid=(pid) ⇒ Object
Override pid setter to clear cached object instance variable.
-
#success! ⇒ Object
Outcome methods.
- #success? ⇒ Boolean
- #user=(user) ⇒ Object
Class Method Details
.call(*args) ⇒ Object
Receive message sent by ActiveSupport::Notifications
40 41 42 43 44 45 46 |
# File 'lib/ddr/events/event.rb', line 40 def self.call(*args) notification = ActiveSupport::Notifications::Event.new(*args) if block_given? yield notification.payload end create(notification.payload) end |
.for_object(obj) ⇒ Object
Scopes
50 51 52 |
# File 'lib/ddr/events/event.rb', line 50 def self.for_object(obj) for_pid(obj.id) end |
.for_pid(pid) ⇒ Object
54 55 56 |
# File 'lib/ddr/events/event.rb', line 54 def self.for_pid(pid) where(pid: pid) end |
Instance Method Details
#comment_or_summary ⇒ Object
69 70 71 |
# File 'lib/ddr/events/event.rb', line 69 def comment_or_summary comment.present? ? comment : summary end |
#display_type ⇒ Object
Rendering methods
60 61 62 63 |
# File 'lib/ddr/events/event.rb', line 60 def display_type # Ddr::Events::UpdateEvent => "Update" @display_type ||= self.class.to_s.split("::").last.sub("Event", "").titleize end |
#event_date_time_s ⇒ Object
Return a date/time formatted as a string suitable for use as a PREMIS eventDateTime. Format also works for Solr. Force to UTC.
111 112 113 |
# File 'lib/ddr/events/event.rb', line 111 def event_date_time_s event_date_time.utc.strftime DATE_TIME_FORMAT end |
#failure! ⇒ Object
83 84 85 |
# File 'lib/ddr/events/event.rb', line 83 def failure! self.outcome = FAILURE end |
#failure? ⇒ Boolean
87 88 89 |
# File 'lib/ddr/events/event.rb', line 87 def failure? outcome == FAILURE end |
#object ⇒ Object
Object getter and setter
92 93 94 |
# File 'lib/ddr/events/event.rb', line 92 def object @object ||= ActiveFedora::Base.find(pid) if pid end |
#object=(obj) ⇒ Object
96 97 98 99 100 |
# File 'lib/ddr/events/event.rb', line 96 def object=(obj) raise ArgumentError, "Can't set to new object" if obj.new_record? self.pid = obj.id @object = obj end |
#performed_by ⇒ Object
65 66 67 |
# File 'lib/ddr/events/event.rb', line 65 def performed_by user_key || SYSTEM end |
#pid=(pid) ⇒ Object
Override pid setter to clear cached object instance variable
103 104 105 106 |
# File 'lib/ddr/events/event.rb', line 103 def pid=(pid) @object = nil super end |
#success! ⇒ Object
Outcome methods
75 76 77 |
# File 'lib/ddr/events/event.rb', line 75 def success! self.outcome = SUCCESS end |
#success? ⇒ Boolean
79 80 81 |
# File 'lib/ddr/events/event.rb', line 79 def success? outcome == SUCCESS end |
#user=(user) ⇒ Object
115 116 117 |
# File 'lib/ddr/events/event.rb', line 115 def user=(user) self.user_key = user.user_key end |