Class: Ticket

Inherits:
Object
  • Object
show all
Defined in:
lib/ticket.rb

Instance Method Summary collapse

Constructor Details

#initialize(database, id) ⇒ Ticket

Returns a new instance of Ticket.



2
3
4
5
6
# File 'lib/ticket.rb', line 2

def initialize(database, id)
    @db = database
    @ticketid = id
    refresh
end

Instance Method Details

#comment_idObject



34
35
36
# File 'lib/ticket.rb', line 34

def comment_id
    @comment_id ||= select("tkt_id")
end

#commentsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ticket.rb', line 44

def comments
    if(!@comments)
        old = old_comments
        res = @db.execute("select icomment from ticketchng where tkt_id is ?", comment_id)
        if(res)
            @comments = old+res.join
        else
            @comments = old+""
        end
        @comments.gsub!(/\r\n/, "\n")
    end
    @comments
end

#idObject



74
75
76
# File 'lib/ticket.rb', line 74

def id
    @ticketid
end

#match(regex) ⇒ Object



88
89
90
# File 'lib/ticket.rb', line 88

def match(regex)
    (comments && comments.match(regex)) || (title && title.match(regex))
end

#old_commentsObject



38
39
40
41
# File 'lib/ticket.rb', line 38

def old_comments
    res   = select("comment")
    res ||= ""
end

#priorityObject



58
59
60
# File 'lib/ticket.rb', line 58

def priority
    @priority ||= select("priority")
end

#refreshObject



78
79
80
81
82
83
84
85
86
# File 'lib/ticket.rb', line 78

def refresh
    @title      = nil
    @status     = nil
    @type       = nil
    @subsystem  = nil
    @priority   = nil
    @resolution = nil
    @comments   = nil
end

#resolutionObject



62
63
64
# File 'lib/ticket.rb', line 62

def resolution
    @resolution ||= select("resolution")
end

#resolveObject



67
68
69
70
71
72
# File 'lib/ticket.rb', line 67

def resolve
    if(status == "Open")
        `fossil ticket set #{@ticketid} status Fixed`
        @status = nil
    end
end

#select(field) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/ticket.rb', line 8

def select(field)
    result = nil
    @db.execute(
        "select #{field} from ticket where tkt_uuid is ?",
        @ticketid.to_s) do |val|
            result = val[0]
        end
    result
end

#statusObject



22
23
24
# File 'lib/ticket.rb', line 22

def status
    @status ||= select("status")
end

#subsystemObject



30
31
32
# File 'lib/ticket.rb', line 30

def subsystem
    @subsystem ||= select("subsystem")
end

#titleObject



18
19
20
# File 'lib/ticket.rb', line 18

def title
    @title ||= select("title")
end

#typeObject



26
27
28
# File 'lib/ticket.rb', line 26

def type
    @type ||= select("type")
end