dm-keeper-adapter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,6 @@ require "dm-keeper-adapter/update"
8
8
  require "dm-keeper-adapter/delete"
9
9
  require "dm-keeper-adapter/misc"
10
10
 
11
-
12
11
  module DataMapper
13
12
  class Property
14
13
  autoload :XML, "property/xml"
@@ -1,4 +1,7 @@
1
1
  # read.rb
2
+
3
+ require 'cgi'
4
+
2
5
  module DataMapper::Adapters
3
6
  class KeeperAdapter < AbstractAdapter
4
7
  require 'nokogiri'
@@ -53,13 +56,13 @@ module DataMapper::Adapters
53
56
  #
54
57
  # @api private
55
58
  def perform_query(query, operand)
56
- # $stderr.puts "perform_query(#{query},#{operand})"
57
59
  records = []
58
-
59
- if operand.is_a?(DataMapper::Query::Conditions::NotOperation)
60
+
61
+ case operand
62
+ when DataMapper::Query::Conditions::NotOperation
60
63
  subject = operand.first.subject
61
64
  value = operand.first.value
62
- elsif operand.subject.is_a?(DataMapper::Associations::ManyToOne::Relationship)
65
+ when DataMapper::Associations::ManyToOne::Relationship
63
66
  subject = operand.subject.child_key.first
64
67
  value = operand.value[operand.subject.parent_key.first.name]
65
68
  else
@@ -71,6 +74,8 @@ module DataMapper::Adapters
71
74
  subject = subject.child_key.first
72
75
  end
73
76
 
77
+ # $stderr.puts "perform_query(\n\tsubject#{subject.inspect}\n\t#{value.inspect})"
78
+
74
79
  # typical queries
75
80
  #
76
81
  # ?query=/feature[
@@ -79,7 +84,7 @@ module DataMapper::Adapters
79
84
  # ]
80
85
  # and
81
86
  # actor[
82
- # (person/userid='kkaempf@novell.com' or person/email='kkaempf@novell.com' or person/fullname='kkaempf@novell.com')
87
+ # (person/userid='kkaempf@suse.com' or person/email='kkaempf@suse.com' or person/fullname='kkaempf@suse.com')
83
88
  # and
84
89
  # role='projectmanager'
85
90
  # ]
@@ -98,18 +103,23 @@ module DataMapper::Adapters
98
103
  container = query.model.to_s.downcase
99
104
  if query.model.key.include?(subject)
100
105
  # get single <feature>
101
- records << node_to_record(query.model, get("/#{container}/#{value}").root)
106
+ records << node_to_record(query.model, get("/#{container}/#{CGI.escape(value.to_s)}").root)
102
107
  else
103
108
  # query, get <collection>[<object><feature>...]*
104
109
  xpath = "/#{container}["
105
- # ...
110
+ case operand
111
+ when DataMapper::Query::Conditions::EqualToComparison
112
+ xpath << "contains(#{subject.name},'#{CGI.escape(value)}')"
113
+ else
114
+ raise "Unhandled operand #{operand.class}"
115
+ end
106
116
  xpath << "]"
107
- collection = get("/#{container}?query=#{xpath}")
108
- collection.xpath("/#{container}").each do |feature|
109
- records << node_to_record(query.model, feature)
117
+ collection = get("/#{container}?query=#{xpath}").root
118
+ collection.xpath("//#{container}", collection.namespace).each do |node|
119
+ records << node_to_record(query.model, node)
110
120
  end
111
121
  end
112
-
122
+
113
123
  records
114
124
  end # def
115
125
 
@@ -3,6 +3,6 @@ require 'dm-core/adapters/abstract_adapter'
3
3
 
4
4
  module DataMapper::Adapters
5
5
  class KeeperAdapter < AbstractAdapter
6
- VERSION = "0.0.1"
6
+ VERSION = "0.0.2"
7
7
  end
8
8
  end
@@ -2,18 +2,26 @@ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class Get_relationtree_test < Test::Unit::TestCase
4
4
 
5
- def test_get_relationtree
5
+ def setup
6
6
  DataMapper::Logger.new(STDOUT, :debug)
7
- keeper = DataMapper.setup(:default,
7
+ @keeper = DataMapper.setup(:default,
8
8
  :adapter => 'keeper',
9
9
  :url => 'https://keeper.novell.com/sxkeeper')
10
10
 
11
11
  require 'keeper/relationtree'
12
12
  DataMapper.finalize
13
+ end
13
14
 
15
+ def test_get_relationtree_by_id
16
+ # Access relationtree by id
14
17
  tree = Relationtree.get(1137)
15
18
  assert tree
16
- puts "Relationtree #{tree.inspect}"
17
19
  end
18
20
 
21
+ def test_get_relationtree_by_name
22
+ # Access relationtree by name
23
+ tree = Relationtree.first(:title => "Manager 1.2.1")
24
+ assert tree
25
+ assert_equal 1137, tree.id
26
+ end
19
27
  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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Klaus K\xC3\xA4mpf"