Class: Ddr::Events::Event
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ddr::Events::Event
show all
- Defined in:
- lib/ddr/events/event.rb
Constant Summary
collapse
- DATE_TIME_FORMAT =
Event date time - for PREMIS and Solr
"%Y-%m-%dT%H:%M:%S.%LZ"
- DEFAULT_SORT_ORDER =
"event_date_time ASC"
- SUCCESS =
"success"
- FAILURE =
"failure"
- OUTCOMES =
[SUCCESS, FAILURE]
- VALID =
"VALID"
- INVALID =
"INVALID"
- SYSTEM =
For rendering “performed by” when no associated user
"SYSTEM"
- DDR_SOFTWARE =
"ddr-models #{Ddr::Models::VERSION}"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.call(*args) ⇒ Object
Receive message sent by ActiveSupport::Notifications
40
41
42
43
44
45
46
47
48
|
# File 'lib/ddr/events/event.rb', line 40
def self.call(*args)
notification = ActiveSupport::Notifications::Event.new(*args)
payload = notification.payload.dup
payload[:event_date_time] ||= notification.time
create do |event|
event.attributes = payload.select { |k, v| event.has_attribute?(k) }
yield [event, notification] if block_given?
end
end
|
.for_object(obj) ⇒ Object
57
58
59
|
# File 'lib/ddr/events/event.rb', line 57
def self.for_object(obj)
for_pid(obj.pid)
end
|
.for_pid(pid) ⇒ Object
61
62
63
|
# File 'lib/ddr/events/event.rb', line 61
def self.for_pid(pid)
where(pid: pid)
end
|
.repository_software ⇒ Object
Repository software version – e.g., “Fedora Repository 3.7.0”
51
52
53
54
55
|
# File 'lib/ddr/events/event.rb', line 51
def self.repository_software
@@repository_software ||= ActiveFedora::Base.connection_for_pid(0).repository_profile
.values_at(:repositoryName, :repositoryVersion)
.join(" ")
end
|
Instance Method Details
74
75
76
|
# File 'lib/ddr/events/event.rb', line 74
def
.present? ? : summary
end
|
#display_type ⇒ Object
65
66
67
68
|
# File 'lib/ddr/events/event.rb', line 65
def display_type
@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.
113
114
115
|
# File 'lib/ddr/events/event.rb', line 113
def event_date_time_s
event_date_time.utc.strftime DATE_TIME_FORMAT
end
|
#failure! ⇒ Object
86
87
88
|
# File 'lib/ddr/events/event.rb', line 86
def failure!
self.outcome = FAILURE
end
|
#failure? ⇒ Boolean
90
91
92
|
# File 'lib/ddr/events/event.rb', line 90
def failure?
outcome == FAILURE
end
|
#object ⇒ Object
94
95
96
|
# File 'lib/ddr/events/event.rb', line 94
def object
@object ||= ActiveFedora::Base.find(pid) if pid
end
|
#object=(obj) ⇒ Object
98
99
100
101
102
|
# File 'lib/ddr/events/event.rb', line 98
def object=(obj)
raise ArgumentError, "Can't set to new object" if obj.new_record?
self.pid = obj.pid
@object = obj
end
|
70
71
72
|
# File 'lib/ddr/events/event.rb', line 70
def performed_by
user_key || SYSTEM
end
|
#pid=(pid) ⇒ Object
Override pid setter to clear cached object instance variable
105
106
107
108
|
# File 'lib/ddr/events/event.rb', line 105
def pid=(pid)
@object = nil
super
end
|
#success! ⇒ Object
78
79
80
|
# File 'lib/ddr/events/event.rb', line 78
def success!
self.outcome = SUCCESS
end
|
#success? ⇒ Boolean
82
83
84
|
# File 'lib/ddr/events/event.rb', line 82
def success?
outcome == SUCCESS
end
|
#user=(user) ⇒ Object
117
118
119
|
# File 'lib/ddr/events/event.rb', line 117
def user=(user)
self.user_key = user.user_key
end
|