lib/om/xml/container.rb in om-1.6.1 vs lib/om/xml/container.rb in om-1.7.0.rc1

- old
+ new

@@ -1,6 +1,7 @@ module OM::XML::Container + extend ActiveSupport::Concern attr_accessor :ng_xml # Class Methods -- These methods will be available on classes that include this Module @@ -9,11 +10,11 @@ # @xml String, File or Nokogiri::XML::Node # @tmpl ActiveFedora::MetadataDatastream # Careful! If you call this from a constructor, be sure to provide something 'ie. self' as the @tmpl. Otherwise, you will get an infinite loop! def from_xml(xml=nil, tmpl=self.new) # :nodoc: if xml.nil? - tmpl.ng_xml = self.xml_template + # noop: handled in #ng_xml accessor.. tmpl.ng_xml = self.xml_template elsif xml.kind_of? Nokogiri::XML::Node tmpl.ng_xml = xml else tmpl.ng_xml = Nokogiri::XML::Document.parse(xml) end @@ -28,16 +29,16 @@ Nokogiri::XML::Document.parse("") end end + def ng_xml + @ng_xml ||= self.class.xml_template + end + # Instance Methods -- These methods will be available on instances of classes that include this module - def self.included(klass) - klass.extend(ClassMethods) - end - def to_xml(xml = ng_xml) if xml == ng_xml return xml.to_xml elsif ng_xml.root.nil? return xml.to_xml @@ -50,6 +51,6 @@ else raise "You can only pass instances of Nokogiri::XML::Node into this method. You passed in #{xml}" end end -end \ No newline at end of file +end