dm-keeper-adapter 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/dm-keeper-adapter/read.rb +7 -13
- data/lib/dm-keeper-adapter/version.rb +1 -1
- data/lib/keeper/relation.rb +8 -3
- data/lib/keeper/relationtree.rb +28 -2
- data/test/test_get_relationtree.rb +13 -1
- metadata +4 -4
@@ -57,12 +57,12 @@ module DataMapper::Adapters
|
|
57
57
|
# @api private
|
58
58
|
def perform_query(query, operand)
|
59
59
|
records = []
|
60
|
+
# STDERR.puts "perform_query(query#{query}, operand #{operand})"
|
60
61
|
|
61
|
-
|
62
|
-
when DataMapper::Query::Conditions::NotOperation
|
62
|
+
if operand.is_a? DataMapper::Query::Conditions::NotOperation
|
63
63
|
subject = operand.first.subject
|
64
64
|
value = operand.first.value
|
65
|
-
|
65
|
+
elsif operand.subject.is_a? DataMapper::Associations::ManyToOne::Relationship
|
66
66
|
subject = operand.subject.child_key.first
|
67
67
|
value = operand.value[operand.subject.parent_key.first.name]
|
68
68
|
else
|
@@ -141,6 +141,10 @@ module DataMapper::Adapters
|
|
141
141
|
model.properties.each do |property|
|
142
142
|
xpath = xpathmap[property.name] || property.name
|
143
143
|
key = property.name.to_s
|
144
|
+
if key == "raw"
|
145
|
+
record[key] = node.to_s
|
146
|
+
next
|
147
|
+
end
|
144
148
|
children = node.xpath("./#{xpath}", xmlnamespaces)
|
145
149
|
# $stderr.puts "Property found: #{property.inspect}"
|
146
150
|
case children.size
|
@@ -162,16 +166,6 @@ module DataMapper::Adapters
|
|
162
166
|
raise TypeError, "#{property} unsupported"
|
163
167
|
end
|
164
168
|
end
|
165
|
-
model.relationships.each do |rel|
|
166
|
-
# $stderr.puts "Rel ? #{rel.inspect}"
|
167
|
-
children = node.xpath("./#{rel.child_model_name.downcase}")
|
168
|
-
value = []
|
169
|
-
while n = children.shift
|
170
|
-
value << node_to_record(rel.child_model, n)
|
171
|
-
end
|
172
|
-
record[rel.name.to_s] = value
|
173
|
-
# $stderr.puts "#{rel.name} -> #{value.inspect}"
|
174
|
-
end
|
175
169
|
record
|
176
170
|
end
|
177
171
|
end # class
|
data/lib/keeper/relation.rb
CHANGED
@@ -7,7 +7,12 @@ class Relation
|
|
7
7
|
end
|
8
8
|
property :target, Integer, :key => true
|
9
9
|
property :sort_position, Integer
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# workaround for non-working associations
|
11
|
+
property :parent, Integer
|
12
|
+
|
13
|
+
# this is how it should be - how to implement it in the adapter ??
|
14
|
+
# has 1, :parent, self
|
15
|
+
# belongs_to :relation, :required => false
|
16
|
+
# has n, :children, self
|
17
|
+
# belongs_to :relationtree, :required => false
|
13
18
|
end
|
data/lib/keeper/relationtree.rb
CHANGED
@@ -15,6 +15,32 @@ class Relationtree
|
|
15
15
|
property :id, Integer, :key => true
|
16
16
|
property :title, String
|
17
17
|
property :description, String
|
18
|
-
|
19
|
-
|
18
|
+
property :raw, String
|
19
|
+
# fixme: has n, :relations
|
20
|
+
|
21
|
+
#
|
22
|
+
# Workaround for missing association (see relation.rb)
|
23
|
+
# Save relationtree xml in 'raw' and parse it when 'Relationtree#relations' is accessed
|
24
|
+
# (should be a DataMapper::Associations::OneToMany::Collection :-/ )
|
25
|
+
#
|
26
|
+
|
27
|
+
def node2relation node, parent = nil
|
28
|
+
rel = Relation.new( :target => node["target"] , :sort_position => node["sortPosition"], :parent => (parent) ? parent.target : nil)
|
29
|
+
node.element_children.each do |child|
|
30
|
+
relchild = node2relation(child, rel)
|
31
|
+
end
|
32
|
+
rel
|
33
|
+
end
|
34
|
+
|
35
|
+
# convert 'raw' into Relations
|
36
|
+
def relations
|
37
|
+
retval = []
|
38
|
+
require 'nokogiri'
|
39
|
+
xml = Nokogiri::XML.parse @raw
|
40
|
+
parent = nil
|
41
|
+
xml.root.xpath("/relationtree/relation").each do |rel|
|
42
|
+
retval << node2relation(rel)
|
43
|
+
end
|
44
|
+
retval
|
45
|
+
end
|
20
46
|
end
|
@@ -12,7 +12,7 @@ class Get_relationtree_test < Test::Unit::TestCase
|
|
12
12
|
DataMapper.finalize
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def xtest_get_relationtree_by_id
|
16
16
|
# Access relationtree by id
|
17
17
|
tree = Relationtree.get(1137)
|
18
18
|
assert tree
|
@@ -22,6 +22,18 @@ class Get_relationtree_test < Test::Unit::TestCase
|
|
22
22
|
# Access relationtree by name
|
23
23
|
tree = Relationtree.first(:title => "Manager 1.2.1")
|
24
24
|
assert tree
|
25
|
+
assert tree.title
|
26
|
+
assert tree.description
|
25
27
|
assert_equal 1137, tree.id
|
28
|
+
# lazy-load relations
|
29
|
+
assert tree.relations
|
30
|
+
assert tree.relations.size > 0
|
31
|
+
tree.relations.each do |rel|
|
32
|
+
# puts rel.inspect
|
33
|
+
# puts "Parent #{rel.parent}"
|
34
|
+
# puts "Children #{rel.children.size}"
|
35
|
+
assert rel.target
|
36
|
+
assert rel.sort_position
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-keeper-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Klaus K\xC3\xA4mpf"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-28 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|