powirb 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -29,5 +29,5 @@ end
29
29
 
30
30
  desc "Release gem to RubyGems.org"
31
31
  task :release => :build do
32
- #system "gem push powirb-#{Powirb::VERSION}"
32
+ system "gem push powirb-#{Powirb::VERSION}.gem"
33
33
  end
@@ -13,31 +13,31 @@ class Handler
13
13
  # Initialize the handler with the project path (usually a subversion
14
14
  # working copy)
15
15
  def initialize(project_path)
16
- unless File.exist?(project_path)
17
- msg = "Invalid project path '#{project_path}'"
18
- Powirb.log.error(msg)
19
- raise msg
20
- end
16
+ unless File.exist?(project_path)
17
+ msg = "Invalid project path '#{project_path}'"
18
+ Powirb.log.error(msg)
19
+ raise msg
20
+ end
21
21
  @project_path = project_path
22
- Powirb.log.debug("Initialized handler for #{@project_path}")
22
+ Powirb.log.debug("Initialized handler for #{@project_path}")
23
23
 
24
- @workitems_count = 0
25
- self.workitems_paths.each do |path|
26
- @workitems_count += Dir[@project_path + path + "/**/workitem.xml"].size
27
- end
28
- Powirb.log.debug("Found #{@workitems_count} workitems.")
24
+ @workitems_count = 0
25
+ self.workitems_paths.each do |path|
26
+ @workitems_count += Dir[File.join(@project_path, path, "/**/workitem.xml")].size
27
+ end
28
+ Powirb.log.debug("Found #{@workitems_count} workitems.")
29
29
  end
30
30
 
31
31
  # Return all workitems in the project
32
32
  def workitems
33
- tmp = []
34
- self.workitems_paths.each do |path|
35
- Dir[@project_path + path + "/**/workitem.xml"].each do |filename|
36
- tmp << Workitem.new(filename)
37
- Powirb.log.debug("Added workitem from #{filename}")
33
+ tmp = []
34
+ self.workitems_paths.each do |path|
35
+ Dir[File.join(@project_path, path, "/**/workitem.xml")].each do |filename|
36
+ tmp << Workitem.new(filename)
37
+ Powirb.log.debug("Added workitem from #{filename}")
38
+ end
38
39
  end
39
- end
40
- tmp
40
+ tmp
41
41
  end
42
42
 
43
43
  # Return the number of total workitems found in the project
@@ -47,7 +47,8 @@ class Handler
47
47
 
48
48
  # Returns the path for workitems in the specified project
49
49
  def workitems_paths
50
- ["/.polarion/tracker/workitems", "/modules/**/workitems"]
50
+ [ File.join('.polarion', 'tracker', 'workitems'),
51
+ File.join('modules', '**', 'workitems') ]
51
52
  end
52
53
  end
53
54
 
@@ -1,4 +1,4 @@
1
1
  module Powirb
2
- VERSION = '1.0'
2
+ VERSION = '1.1'
3
3
  end
4
4
 
@@ -15,46 +15,46 @@ class Workitem
15
15
  # in the standard way Polarion does it
16
16
  def initialize(filename)
17
17
  @filename = filename
18
- Powirb.log.debug("Initializing workitem with #{filename}")
18
+ Powirb.log.debug("Initializing workitem with #{filename}")
19
19
  end
20
20
 
21
21
  # Read workitem content
22
22
  def read
23
23
  Powirb.log.debug("Retrieving workitem from #{@filename}")
24
24
  begin
25
- @doc = Nokogiri::XML(open(@filename))
26
- rescue Exception => e
27
- Powirb.log.error(e)
28
- end
25
+ @doc = Nokogiri::XML(open(@filename))
26
+ rescue Exception => e
27
+ Powirb.log.error(e)
28
+ end
29
29
  end
30
30
 
31
31
  # Return a field value
32
32
  def [](fname)
33
33
  fname = fname.to_s
34
34
  node = @doc.xpath("//field[@id=\"#{fname}\"]")
35
- return nil if node.text.empty?
36
- node.text
35
+ return nil if node.text.empty?
36
+ node.text
37
37
  end
38
38
 
39
39
  # Set/remove a field
40
40
  def []=(fname, fvalue)
41
41
  fname = fname.to_s
42
42
  if self[fname].nil?
43
- # inserting new field
44
- Powirb.log.debug("[#{wid}] adding new field '#{fname}' with value '#{fvalue}'")
45
- @doc.xpath('//field[@id="type"]').last.add_next_sibling("\n <field id=\"#{fname}\">#{fvalue}</field>")
43
+ # inserting new field
44
+ Powirb.log.debug("[#{wid}] adding new field '#{fname}' with value '#{fvalue}'")
45
+ @doc.xpath('//field[@id="type"]').last.add_next_sibling("\n <field id=\"#{fname}\">#{fvalue}</field>")
46
46
  else
47
- if fvalue.nil?
48
- # removing existing field
49
- Powirb.log.debug("[#{wid}] removing field '#{fname}'")
50
- @doc.xpath("//field[@id=\"#{fname}\"]").last.remove
51
- else
52
- # updating existing field
53
- Powirb.log.debug("[#{wid}] updating field '#{fname}' with value '#{fvalue}'")
54
- e = @doc.xpath("//field[@id=\"#{fname}\"]").last
55
- e.content = fvalue
47
+ if fvalue.nil?
48
+ # removing existing field
49
+ Powirb.log.debug("[#{wid}] removing field '#{fname}'")
50
+ @doc.xpath("//field[@id=\"#{fname}\"]").last.remove
51
+ else
52
+ # updating existing field
53
+ Powirb.log.debug("[#{wid}] updating field '#{fname}' with value '#{fvalue}'")
54
+ e = @doc.xpath("//field[@id=\"#{fname}\"]").last
55
+ e.content = fvalue
56
+ end
56
57
  end
57
- end
58
58
  end
59
59
 
60
60
  # Save workitem on filesystem
@@ -67,6 +67,16 @@ class Workitem
67
67
  def wid
68
68
  File.basename(File.dirname(@filename))
69
69
  end
70
+
71
+ # Return XML content
72
+ def to_xml
73
+ @doc.to_xml
74
+ end
75
+
76
+ # Return a list with all field names
77
+ def fields
78
+ @doc.xpath("//field").map{|node| node['id']}.sort
79
+ end
70
80
  end
71
81
 
72
82
  end
data/lib/powirb.rb CHANGED
@@ -23,21 +23,21 @@ module Powirb
23
23
  # +filename+ if not specified STDOUT is used
24
24
  def self.set_logger(level, filename=STDOUT)
25
25
  @logger = Logger.new(filename)
26
- @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
27
- @logger.level = case level.to_s
28
- when 'debug'
29
- Logger::DEBUG
30
- when 'info'
31
- Logger::INFO
32
- when 'warn'
33
- Logger::WARN
34
- when 'error'
35
- Logger::ERROR
36
- when 'fatal'
37
- Logger::FATAL
38
- else
39
- Logger::WARN
40
- end
26
+ @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
27
+ @logger.level = case level.to_s
28
+ when 'debug'
29
+ Logger::DEBUG
30
+ when 'info'
31
+ Logger::INFO
32
+ when 'warn'
33
+ Logger::WARN
34
+ when 'error'
35
+ Logger::ERROR
36
+ when 'fatal'
37
+ Logger::FATAL
38
+ else
39
+ Logger::WARN
40
+ end
41
41
  end
42
42
 
43
43
  # we have to provide a default logger
data/powirb.gemspec CHANGED
@@ -1,7 +1,8 @@
1
1
 
2
+
2
3
  Gem::Specification.new do |s|
3
4
  s.name = "powirb"
4
- s.version = "1.0"
5
+ s.version = "1.1"
5
6
  s.summary = "POlarion WorkItems handling with RuBy"
6
7
  s.description = <<-EOF
7
8
  Ruby interface to Polarion workitems content, for fast manipulation.
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
+ require 'Nokogiri'
2
3
 
3
4
  class PowirbWorkitemTest < Test::Unit::TestCase
4
5
 
@@ -70,5 +71,17 @@ class PowirbWorkitemTest < Test::Unit::TestCase
70
71
  w.read
71
72
  assert_nil w['priority']
72
73
  end
73
-
74
+
75
+ def test_xml
76
+ xml = @wi.to_xml
77
+ assert_kind_of String, xml
78
+ assert xml.include?("<field id=\"title\">#{@wi[:title]}</field>")
79
+ end
80
+
81
+ def test_fields
82
+ fields = @wi.fields
83
+ assert_kind_of Array, fields
84
+ assert fields.include?('title')
85
+ assert !fields.include?('foo')
86
+ end
74
87
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: powirb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 0
9
- version: "1.0"
8
+ - 1
9
+ version: "1.1"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Carlo Pecchia
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-11 00:00:00 +02:00
17
+ date: 2011-04-18 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency