Class: Dor::EventsDS

Inherits:
ActiveFedora::OmDatastream
  • Object
show all
Defined in:
lib/dor/datastreams/events_ds.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.xml_templateObject

Default EventsDS xml



18
19
20
21
22
23
# File 'lib/dor/datastreams/events_ds.rb', line 18

def self.xml_template
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.events
  end
  builder.doc
end

Instance Method Details

#add_event(type, who, message) ⇒ Object

Adds an event to the datastream

Parameters:

  • type (String)

    a tag used to group events together. Sets the type attribute for the event

  • who (String)

    who is responsible for this event. Sets the who attribute for the event

  • message (String)

    what happened. Sets the content of the event with this message



33
34
35
36
37
38
# File 'lib/dor/datastreams/events_ds.rb', line 33

def add_event(type, who, message)
  ng_xml_will_change!
  ev = ng_xml.create_element 'event', message,
                             type: type, who: who, when: Time.now.utc.xmlschema
  ng_xml.root.add_child(ev)
end

#each_event {|type, who, timestamp, message| ... } ⇒ Object

Returns all the events in the datastream

Yields:

  • (type, who, timestamp, message)

    The values of the current event

Yield Parameters:

  • type (String)

    tag for this particular event. Value of the ‘type’ attribute

  • who (String)

    thing responsible for creating the event. Value of the ‘who’ attribute

  • timestamp (Time)

    when this event was logged. Value of the ‘when’ attribute

  • message (String)

    what happened. Content of the event node



58
59
60
61
62
# File 'lib/dor/datastreams/events_ds.rb', line 58

def each_event
  find_by_terms(:event).each do |node|
    yield(node['type'], node['who'], Time.parse(node['when']), node.content)
  end
end

#ensure_non_versionableObject



25
26
27
# File 'lib/dor/datastreams/events_ds.rb', line 25

def ensure_non_versionable
  self.versionable = 'false'
end

#find_events_by_type(tag) {|who, timestamp, message| ... } ⇒ Object

Finds events with the desired type attribute

Parameters:

  • tag (String)

    events where type == tag will be returned

Yields:

  • (who, timestamp, message)

    The values of the current event

Yield Parameters:

  • who (String)

    thing responsible for creating the event. Value of the ‘who’ attribute

  • timestamp (Time)

    when this event was logged. Value of the ‘when’ attribute

  • message (String)

    what happened. Content of the event node



46
47
48
49
50
# File 'lib/dor/datastreams/events_ds.rb', line 46

def find_events_by_type(tag)
  find_by_terms(:event).xpath("//event[@type='#{tag}']").each do |node|
    yield(node['who'], Time.parse(node['when']), node.content)
  end
end

#prefixObject

maintain AF < 8 indexing behavior



65
66
67
# File 'lib/dor/datastreams/events_ds.rb', line 65

def prefix
  ''
end