Class: Trac::Ticket

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

Overview

This class represents a ticket as it is retrieved from the database Custom fields are detected and available via runtime-dispatched methods.

See method_missing

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = 0) ⇒ Ticket

returns a new ticket



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

def initialize id=0
  @id = id
  @severity=@milestone=@status=@type=@priority=@version=@reporter=@owner= @cc= @summary=@description=@keywords=""
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object

If a method call has no args and matches an instance variable, we return its value. e.g. if our tickets have a custom field called work_units, then some_ticket.work_units will retrieve that value. This currently only allows retrieval and not updating the value.



40
41
42
43
44
45
46
# File 'lib/trac4r/ticket.rb', line 40

def method_missing(sym,*args)
  if args.size == 0 && instance_variables.include?("@" + sym.to_s)
    instance_eval("@" + sym.to_s)
  else
    super.method_missing(sym,args)
  end
end

Instance Attribute Details

#ccObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def cc
  @cc
end

#created_atObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def created_at
  @created_at
end

#descriptionObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def description
  @description
end

#idObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def id
  @id
end

#keywordsObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def keywords
  @keywords
end

#milestoneObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def milestone
  @milestone
end

#ownerObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def owner
  @owner
end

#priorityObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def priority
  @priority
end

#reporterObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def reporter
  @reporter
end

#severityObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def severity
  @severity
end

#statusObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def status
  @status
end

#summaryObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def summary
  @summary
end

#typeObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def type
  @type
end

#updated_atObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def updated_at
  @updated_at
end

#versionObject

Integer



6
7
8
# File 'lib/trac4r/ticket.rb', line 6

def version
  @version
end

Class Method Details

.load(params) ⇒ Object

loads a ticket from the XMLRPC response



49
50
51
52
53
54
55
56
57
58
# File 'lib/trac4r/ticket.rb', line 49

def self.load params
  ticket = self.new params[0]
  ticket.created_at = params[1]
  ticket.updated_at = params[2]
  attributes = params[3]
  attributes.each do |key,value|
    ticket.instance_variable_set("@#{key}".to_sym,value)
  end
  return ticket
end

Instance Method Details

#checkObject

checks if all attributes are set



28
29
30
31
32
33
# File 'lib/trac4r/ticket.rb', line 28

def check
  instance_variables.each do |v|
    return false if instance_variable_get(v.to_sym).nil?
  end
  return true
end