Class: Trac::Ticket
- Inherits:
-
Object
- Object
- Trac::Ticket
- 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
-
#cc ⇒ Object
Integer.
-
#component ⇒ Object
Integer.
-
#created_at ⇒ Object
Integer.
-
#description ⇒ Object
Integer.
-
#id ⇒ Object
Integer.
-
#keywords ⇒ Object
Integer.
-
#milestone ⇒ Object
Integer.
-
#owner ⇒ Object
Integer.
-
#priority ⇒ Object
Integer.
-
#reporter ⇒ Object
Integer.
-
#severity ⇒ Object
Integer.
-
#status ⇒ Object
Integer.
-
#summary ⇒ Object
Integer.
-
#type ⇒ Object
Integer.
-
#updated_at ⇒ Object
Integer.
-
#version ⇒ Object
Integer.
Class Method Summary collapse
-
.load(params) ⇒ Object
loads a ticket from the XMLRPC response.
Instance Method Summary collapse
-
#check ⇒ Object
checks if all attributes are set.
-
#initialize(id = 0) ⇒ Ticket
constructor
returns a new ticket.
-
#method_missing(sym, *args) ⇒ Object
If a method call has no args and matches an instance variable, we return its value.
Constructor Details
#initialize(id = 0) ⇒ Ticket
returns a new ticket
23 24 25 26 |
# File 'lib/trac4r/ticket.rb', line 23 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. Also note that you can retrieve a custom field using “!” and this will silently return nil if the instance variable didn’t exist. This is useful if some tickets just don’t have the custom field, but you don’t wish to check for it
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/trac4r/ticket.rb', line 44 def method_missing(sym,*args) method = sym.to_s method = method[0..-2] if method =~ /!$/ if args.size == 0 && instance_variables.include?("@#{method}".to_sym) instance_eval("@" + sym.to_s) elsif method != sym.to_s nil else super.method_missing(sym,args) end end |
Instance Attribute Details
#cc ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def cc @cc end |
#component ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def component @component end |
#created_at ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def created_at @created_at end |
#description ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def description @description end |
#id ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def id @id end |
#keywords ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def keywords @keywords end |
#milestone ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def milestone @milestone end |
#owner ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def owner @owner end |
#priority ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def priority @priority end |
#reporter ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def reporter @reporter end |
#severity ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def severity @severity end |
#status ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def status @status end |
#summary ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def summary @summary end |
#type ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def type @type end |
#updated_at ⇒ Object
Integer
6 7 8 |
# File 'lib/trac4r/ticket.rb', line 6 def updated_at @updated_at end |
#version ⇒ Object
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
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/trac4r/ticket.rb', line 57 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
#check ⇒ Object
checks if all attributes are set
29 30 31 32 33 34 |
# File 'lib/trac4r/ticket.rb', line 29 def check instance_variables.each do |v| return false if instance_variable_get(v.to_sym).nil? end return true end |