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


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

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

Instance Method Details

#add_event(type, who, message) ⇒ Object

Adds an event to the datastream


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

def add_event(type, who, message)
  ev = ng_xml.create_element "event", message, 
    :type => type, :who => who, :when => Time.now.xmlschema
  ng_xml.root.add_child(ev)
  content_will_change!
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


56
57
58
59
60
# File 'lib/dor/datastreams/events_ds.rb', line 56

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

#ensure_non_versionableObject


23
24
25
# File 'lib/dor/datastreams/events_ds.rb', line 23

def ensure_non_versionable
  self.versionable = "false"
end

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

Finds events with the desired type attribute

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


44
45
46
47
48
# File 'lib/dor/datastreams/events_ds.rb', line 44

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