dm-keeper-adapter 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
- Gemfile
5
4
  pkg/*
6
5
  *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dm-keeper-adapter.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 SUSE LINUX Products GmbH
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -33,8 +33,25 @@ Install it with
33
33
  require 'keeper/feature'
34
34
  DataMapper.finalize
35
35
 
36
+ # Get feature by ID
36
37
  f = Feature.get(311545)
37
38
 
39
+ # Finding features (see http://datamapper.org/docs/find.html)
40
+
41
+ # Get feature by title (assuming there's only one)
42
+ f = Feature.first(:title => "Feature title")
43
+
44
+ # Get all features matching a title string
45
+ features = Feature.all(:title.like => "foobar")
46
+
38
47
  == TODO
39
48
 
40
49
  Real DataMapper queries mapped to XPath
50
+
51
+ == License
52
+
53
+ MIT
54
+
55
+ == Author
56
+
57
+ Klaus Kämpf <kkaempf@suse.com>
@@ -1,3 +1,33 @@
1
+ #
2
+ # dm-keeper-adapter.rb
3
+ #
4
+ # A DataMapper adapter for FATE/features.opensuse.org
5
+ #
6
+ #--
7
+ # Copyright (c) 2011 SUSE LINUX Products GmbH
8
+ #
9
+ # Author: Klaus Kämpf <kkaempf@suse.com>
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining
12
+ # a copy of this software and associated documentation files (the
13
+ # "Software"), to deal in the Software without restriction, including
14
+ # without limitation the rights to use, copy, modify, merge, publish,
15
+ # distribute, sublicense, and/or sell copies of the Software, and to
16
+ # permit persons to whom the Software is furnished to do so, subject to
17
+ # the following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be
20
+ # included in all copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ #++
30
+
1
31
  require 'rubygems'
2
32
  require 'dm-core'
3
33
  require 'dm-core/adapters/abstract_adapter'
@@ -1,4 +1,32 @@
1
- # read.rb
1
+ #
2
+ # dm-keeper-adapter/read.rb
3
+ #
4
+ # Read/Query operations - A DataMapper adapter for FATE/features.opensuse.org
5
+ #
6
+ #--
7
+ # Copyright (c) 2011 SUSE LINUX Products GmbH
8
+ #
9
+ # Author: Klaus Kämpf <kkaempf@suse.com>
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining
12
+ # a copy of this software and associated documentation files (the
13
+ # "Software"), to deal in the Software without restriction, including
14
+ # without limitation the rights to use, copy, modify, merge, publish,
15
+ # distribute, sublicense, and/or sell copies of the Software, and to
16
+ # permit persons to whom the Software is furnished to do so, subject to
17
+ # the following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be
20
+ # included in all copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ #++
2
30
 
3
31
  require 'cgi'
4
32
 
@@ -105,11 +133,16 @@ module DataMapper::Adapters
105
133
  # get single <feature>
106
134
  records << node_to_record(query.model, get("/#{container}/#{CGI.escape(value.to_s)}").root)
107
135
  else
136
+ xpath = "/#{container}"
137
+ xpathmap = query.model.xpathmap rescue { }
138
+ name = xpathmap[subject.name] || subject.name
108
139
  # query, get <collection>[<object><feature>...]*
109
- xpath = "/#{container}["
140
+ xpath << "["
110
141
  case operand
111
142
  when DataMapper::Query::Conditions::EqualToComparison
112
- xpath << "contains(#{subject.name},'#{CGI.escape(value)}')"
143
+ xpath << CGI.escape("#{name} = \"#{value}\"")
144
+ when DataMapper::Query::Conditions::LikeComparison
145
+ xpath << "contains(#{name},'#{CGI.escape(value)}')"
113
146
  else
114
147
  raise "Unhandled operand #{operand.class}"
115
148
  end
@@ -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.3"
6
+ VERSION = "0.0.4"
7
7
  end
8
8
  end
@@ -13,7 +13,9 @@ class Feature
13
13
  :productmgr => "actor[role='productmanager']/person/email",
14
14
  :projectmgr => "actor[role='projectmanager']/person/email",
15
15
  :engmgr => "actor[role='teamleader']/person/email",
16
- :developer => "actor[role='developer']/person/email"
16
+ :developer => "actor[role='developer']/person/email",
17
+ :productid => "productcontext/product/productid",
18
+ :product => "productcontext/product/name"
17
19
  }
18
20
  end
19
21
  def self.xmlnamespaces
@@ -28,4 +30,6 @@ class Feature
28
30
  property :engmgr, String
29
31
  property :developer, String
30
32
  property :milestone, String
33
+ property :productid, String
34
+ property :product, String
31
35
  end
@@ -1,6 +1,31 @@
1
1
  #!/bin/env ruby
2
2
  #
3
3
  # Generate/update class definition for 'Feature'
4
+ #
5
+ #--
6
+ # Copyright (c) 2011 SUSE LINUX Products GmbH
7
+ #
8
+ # Author: Klaus Kämpf <kkaempf@suse.com>
9
+ #
10
+ # Permission is hereby granted, free of charge, to any person obtaining
11
+ # a copy of this software and associated documentation files (the
12
+ # "Software"), to deal in the Software without restriction, including
13
+ # without limitation the rights to use, copy, modify, merge, publish,
14
+ # distribute, sublicense, and/or sell copies of the Software, and to
15
+ # permit persons to whom the Software is furnished to do so, subject to
16
+ # the following conditions:
17
+ #
18
+ # The above copyright notice and this permission notice shall be
19
+ # included in all copies or substantial portions of the Software.
20
+ #
21
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ #++
4
29
 
5
30
  require 'lib/dm-keeper-adapter'
6
31
 
@@ -1,3 +1,28 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2011 SUSE LINUX Products GmbH
4
+ #
5
+ # Author: Klaus Kämpf <kkaempf@suse.com>
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining
8
+ # a copy of this software and associated documentation files (the
9
+ # "Software"), to deal in the Software without restriction, including
10
+ # without limitation the rights to use, copy, modify, merge, publish,
11
+ # distribute, sublicense, and/or sell copies of the Software, and to
12
+ # permit persons to whom the Software is furnished to do so, subject to
13
+ # the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be
16
+ # included in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ #++
1
26
  #
2
27
  # generate or update the class definition for 'Feature'
3
28
  #
@@ -4,6 +4,31 @@
4
4
  # Demo script to extract available 'containers' (aka database tables)
5
5
  # from FATE (keeper.suse.de) using DataMapper
6
6
  #
7
+ #
8
+ #--
9
+ # Copyright (c) 2011 SUSE LINUX Products GmbH
10
+ #
11
+ # Author: Klaus Kämpf <kkaempf@suse.com>
12
+ #
13
+ # Permission is hereby granted, free of charge, to any person obtaining
14
+ # a copy of this software and associated documentation files (the
15
+ # "Software"), to deal in the Software without restriction, including
16
+ # without limitation the rights to use, copy, modify, merge, publish,
17
+ # distribute, sublicense, and/or sell copies of the Software, and to
18
+ # permit persons to whom the Software is furnished to do so, subject to
19
+ # the following conditions:
20
+ #
21
+ # The above copyright notice and this permission notice shall be
22
+ # included in all copies or substantial portions of the Software.
23
+ #
24
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
+ #++
7
32
 
8
33
  $: << File.join(File.dirname(__FILE__), "..", "dm-keeper-adapter", "lib")
9
34
 
@@ -19,4 +44,4 @@ c = Keeper::Container.new keeper
19
44
  c.each do |e|
20
45
  puts e
21
46
  end
22
-
47
+
@@ -1,8 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
- class Get_bug_test < Test::Unit::TestCase
3
+ class Get_feature_test < Test::Unit::TestCase
4
4
 
5
- def test_get_bug
5
+ def test_get_feature
6
6
  DataMapper::Logger.new(STDOUT, :debug)
7
7
  keeper = DataMapper.setup(:default,
8
8
  :adapter => 'keeper',
@@ -13,6 +13,7 @@ class Get_bug_test < Test::Unit::TestCase
13
13
 
14
14
  feature = Feature.get(312814)
15
15
  assert feature
16
+ assert_equal 312814, feature.id
16
17
  puts "Feature #{feature.inspect}"
17
18
  end
18
19
 
@@ -12,7 +12,7 @@ class Get_relationtree_test < Test::Unit::TestCase
12
12
  DataMapper.finalize
13
13
  end
14
14
 
15
- def xtest_get_relationtree_by_id
15
+ def test_get_relationtree_by_id
16
16
  # Access relationtree by id
17
17
  tree = Relationtree.get(1137)
18
18
  assert tree
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class Search_feature_test < Test::Unit::TestCase
4
+
5
+ def setup
6
+ DataMapper::Logger.new(STDOUT, :debug)
7
+ @keeper = DataMapper.setup(:default,
8
+ :adapter => 'keeper',
9
+ :url => 'https://keeper.novell.com/sxkeeper')
10
+
11
+ require 'keeper/feature'
12
+ DataMapper.finalize
13
+ end
14
+
15
+ def test_like_feature
16
+ features = Feature.all(:title.like => 'projects')
17
+ assert features
18
+ assert features.size > 0
19
+ puts "#{features.size} features have 'projects' in their title"
20
+ end
21
+
22
+ def test_equal_feature
23
+ features = Feature.all(:title => 'Projects, planning, and priorities')
24
+ assert features
25
+ assert_equal 1, features.size
26
+ f = features[0]
27
+ assert_equal 312814, f.id
28
+ end
29
+
30
+ def test_hackweek7
31
+ f1 = Feature.all(:product => 'Hackweek VII')
32
+ f2 = Feature.all(:productid => 'hackweek_7')
33
+ assert_equal f1.size, f2.size
34
+ puts "#{f1.size} projects registered for Hackweek 7"
35
+ end
36
+
37
+ 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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
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-28 00:00:00 +02:00
18
+ date: 2011-09-29 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -60,6 +60,8 @@ extra_rdoc_files: []
60
60
 
61
61
  files:
62
62
  - .gitignore
63
+ - Gemfile
64
+ - MIT-LICENSE
63
65
  - README.rdoc
64
66
  - Rakefile
65
67
  - dm-keeper-adapter.gemspec
@@ -85,6 +87,7 @@ files:
85
87
  - test/helper.rb
86
88
  - test/test_get_feature.rb
87
89
  - test/test_get_relationtree.rb
90
+ - test/test_search_operator.rb
88
91
  has_rdoc: true
89
92
  homepage: ""
90
93
  licenses: []
@@ -123,3 +126,4 @@ test_files:
123
126
  - test/helper.rb
124
127
  - test/test_get_feature.rb
125
128
  - test/test_get_relationtree.rb
129
+ - test/test_search_operator.rb