Class: Relationtree

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/keeper/relationtree.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.xmlnamespacesObject



12
13
14
# File 'lib/keeper/relationtree.rb', line 12

def self.xmlnamespaces
  { "k" => "http://inttools.suse.de/sxkeeper/schema/keeper" }
end

.xpathmapObject



9
10
11
# File 'lib/keeper/relationtree.rb', line 9

def self.xpathmap
  { :id => "@k:id" }
end

Instance Method Details

#node2relation(node, parent = nil) ⇒ Object

Workaround for missing association (see relation.rb) Save relationtree xml in ‘raw’ and parse it when ‘Relationtree#relations’ is accessed (should be a DataMapper::Associations::OneToMany::Collection :-/ )



27
28
29
30
31
32
33
# File 'lib/keeper/relationtree.rb', line 27

def node2relation node, parent = nil
  rel = Relation.new( :target => node["target"] , :sort_position => node["sortPosition"], :parent => (parent) ? parent.target : nil)
  node.element_children.each do |child|
    relchild = node2relation(child, rel)
  end
  rel
end

#relationsObject

convert ‘raw’ into Relations



36
37
38
39
40
41
42
43
44
45
# File 'lib/keeper/relationtree.rb', line 36

def relations
  retval = []
  require 'nokogiri'
  xml = Nokogiri::XML.parse @raw
  parent = nil
  xml.root.xpath("/relationtree/relation").each do |rel|
    retval << node2relation(rel)
  end
  retval
end