class Ddr::Events::Event
Constants
- DATE_TIME_FORMAT
Event
date time - for PREMIS and Solr- DDR_SOFTWARE
- DEFAULT_SORT_ORDER
set default ordering
- FAILURE
- INVALID
- OUTCOMES
- SUCCESS
Outcomes
- SYSTEM
For rendering “performed by” when no associated user
- VALID
Validation constants
Public Class Methods
call(*args) { |payload| ... }
click to toggle source
Receive message sent by ActiveSupport::Notifications
# 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)
click to toggle source
Scopes
# File lib/ddr/events/event.rb, line 50 def self.for_object(obj) for_pid(obj.id) end
for_pid(pid)
click to toggle source
# File lib/ddr/events/event.rb, line 54 def self.for_pid(pid) where(pid: pid) end
Public Instance Methods
comment_or_summary()
click to toggle source
# File lib/ddr/events/event.rb, line 69 def comment_or_summary comment.present? ? comment : summary end
display_type()
click to toggle source
Rendering methods
# 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()
click to toggle source
Return a date/time formatted as a string suitable for use as a PREMIS eventDateTime. Format also works for Solr. Force to UTC.
# File lib/ddr/events/event.rb, line 111 def event_date_time_s event_date_time.utc.strftime DATE_TIME_FORMAT end
failure!()
click to toggle source
# File lib/ddr/events/event.rb, line 83 def failure! self.outcome = FAILURE end
failure?()
click to toggle source
# File lib/ddr/events/event.rb, line 87 def failure? outcome == FAILURE end
object()
click to toggle source
Object getter and setter
# File lib/ddr/events/event.rb, line 92 def object @object ||= ActiveFedora::Base.find(pid) if pid end
object=(obj)
click to toggle source
# 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()
click to toggle source
# File lib/ddr/events/event.rb, line 65 def performed_by user_key || SYSTEM end
pid=(pid)
click to toggle source
Override pid setter to clear cached object instance variable
Calls superclass method
# File lib/ddr/events/event.rb, line 103 def pid=(pid) @object = nil super end
success!()
click to toggle source
Outcome methods
# File lib/ddr/events/event.rb, line 75 def success! self.outcome = SUCCESS end
success?()
click to toggle source
# File lib/ddr/events/event.rb, line 79 def success? outcome == SUCCESS end
user=(user)
click to toggle source
# File lib/ddr/events/event.rb, line 115 def user=(user) self.user_key = user.user_key end
Protected Instance Methods
default_event_date_time()
click to toggle source
# File lib/ddr/events/event.rb, line 145 def default_event_date_time Time.now.utc end
default_outcome()
click to toggle source
# File lib/ddr/events/event.rb, line 137 def default_outcome SUCCESS end
default_software()
click to toggle source
# File lib/ddr/events/event.rb, line 133 def default_software DDR_SOFTWARE end
default_summary()
click to toggle source
# File lib/ddr/events/event.rb, line 141 def default_summary description end
defaults()
click to toggle source
# File lib/ddr/events/event.rb, line 125 def defaults { event_date_time: default_event_date_time, summary: default_summary, software: default_software, outcome: default_outcome } end
set_defaults()
click to toggle source
# File lib/ddr/events/event.rb, line 121 def set_defaults self.attributes = defaults.reject { |attr, val| attribute_present? attr } end