Class: Dor::EventsDS
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- Dor::EventsDS
- Defined in:
- lib/dor/datastreams/events_ds.rb
Class Method Summary collapse
-
.xml_template ⇒ Object
Default EventsDS xml.
Instance Method Summary collapse
-
#add_event(type, who, message) ⇒ Object
Adds an event to the datastream.
-
#each_event {|type, who, timestamp, message| ... } ⇒ Object
Returns all the events in the datastream.
- #ensure_non_versionable ⇒ Object
-
#find_events_by_type(tag) {|who, timestamp, message| ... } ⇒ Object
Finds events with the desired type attribute.
Class Method Details
.xml_template ⇒ Object
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, ) ev = ng_xml.create_element "event", , :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
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_versionable ⇒ Object
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
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 |