lackac-rira 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION.yml +1 -1
  2. data/lib/rira/base.rb +12 -4
  3. data/lib/rira/model.rb +55 -1
  4. metadata +1 -1
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 3
3
3
  :major: 0
4
4
  :minor: 0
data/lib/rira/base.rb CHANGED
@@ -40,11 +40,12 @@ module Rira
40
40
 
41
41
  def method_missing(method, *args)
42
42
  model, *methods = MAPPINGS[method]
43
-
43
+
44
44
  super(method, *args) if methods.empty?
45
45
 
46
+ retried = false
46
47
  begin
47
- case result = xmlrpc_client.call("jira1.#{methods.shift}", @token, *args)
48
+ case result = xmlrpc_client.call("jira1.#{methods.first}", @token, *args)
48
49
  when Hash
49
50
  model_or_struct(model, result)
50
51
  when Array
@@ -59,8 +60,15 @@ module Rira
59
60
  result
60
61
  end
61
62
  rescue XMLRPC::FaultException => e
62
- retry unless methods.empty?
63
- raise RPCError.new(e)
63
+ if e.faultString =~ /session timed out/ and not retried
64
+ @token = xmlrpc_client.call("jira1.login", @username, @password)
65
+ retried = true
66
+ retry
67
+ else
68
+ methods.shift
69
+ retry unless methods.empty?
70
+ raise RPCError.new(e)
71
+ end
64
72
  end
65
73
  end
66
74
 
data/lib/rira/model.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'time'
2
+
1
3
  module Rira
2
4
  class Model
3
5
  ASSOCIATIONS = {
@@ -16,14 +18,66 @@ module Rira
16
18
  "update_issue"],
17
19
  }
18
20
 
21
+ # FIXME: DRY this up a little bit
22
+ CONVERTERS = {
23
+ 'resolution' => lambda {|s,x| s.base.resolutions.detect {|r| r.id == x}},
24
+ 'priority' => lambda {|s,x| s.base.priorities.detect {|p| p.id == x}},
25
+ 'status' => lambda {|s,x| s.base.statuses.detect {|p| p.id == x}},
26
+ 'project' => lambda {|s,x| s.base.projects.detect {|p| p.key == x}},
27
+ 'type' => lambda { |s,x|
28
+ p = s.project
29
+ (p.issue_types + p.sub_task_issue_types).detect {|it| it.id == x}
30
+ },
31
+ 'lead' => lambda {|s,x| s.base.user(x)},
32
+ 'author' => lambda {|s,x| s.base.user(x)},
33
+ 'reporter' => lambda {|s,x| s.base.user(x)},
34
+ 'assignee' => lambda {|s,x| s.base.user(x)},
35
+ 'components' => lambda {|s,x| x.map {|c| Model.new(s.base, 'component', c)}},
36
+ 'affects_versions' => lambda {|s,x| x.map {|v| Model.new(s.base, 'version', v)}},
37
+ 'fix_versions' => lambda {|s,x| x.map {|v| Model.new(s.base, 'version', v)}},
38
+ 'created' => lambda {|s,x| Time.parse(x)},
39
+ 'updated' => lambda {|s,x| Time.parse(x)},
40
+ 'release_date' => lambda {|s,x| Date.parse(x)},
41
+ 'build_date' => lambda {|s,x| Date.parse(x)},
42
+ 'archived' => lambda {|s,x| x == 'true'},
43
+ 'released' => lambda {|s,x| x == 'true'},
44
+ 'sub_task' => lambda {|s,x| x == 'true'},
45
+ }
46
+
47
+ BOOLEANS = %w{archived released sub_task}
48
+
49
+ attr_reader :base, :model
50
+
19
51
  def initialize(base, model, hash)
20
52
  @base, @model, @attributes = base, model, hash
53
+ @attributes.keys.each do |key|
54
+ new_key = key.gsub(/[A-Z]/) {"_#{$&.downcase}"}
55
+ if key != new_key
56
+ @attributes[new_key] = @attributes.delete(key)
57
+ end
58
+ end
59
+ end
60
+
61
+ def id
62
+ @attributes['id']
63
+ end
64
+
65
+ def type
66
+ CONVERTERS['type'].call(self, @attributes['type'])
21
67
  end
22
68
 
23
69
  def method_missing(method, *args)
24
70
  method = method.to_s
71
+ if method[-1] == ?? and BOOLEANS.include?(method[0..-2])
72
+ method = method[0..-2]
73
+ end
25
74
  if args.empty? and @attributes.has_key?(method)
26
- @attributes[method]
75
+ att = @attributes[method]
76
+ if converter = CONVERTERS[method]
77
+ converter.call(self, att)
78
+ else
79
+ att
80
+ end
27
81
  elsif map = ASSOCIATIONS[method] and map.first == @model
28
82
  _, att, rp = map
29
83
  scope = att[-1] == ?s ? Array(@attributes[att[0..-2]]) : @attributes[att]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lackac-rira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "L\xC3\xA1szl\xC3\xB3 B\xC3\xA1csi"