Class: Rtrac::Ticket

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

columns, config_path, configuration_options, connection, create_new_config, custom, extract_account_info, find_or_create_config, get_by_milestone, get_tickets, home_dir, invalid_config?, list_methods, logger, method_help, open_connection, optional_columns, required_columns, send_query

Constructor Details

#initialize(trac_id, logger = nil) ⇒ Ticket

Returns a new instance of Ticket.



7
8
9
10
# File 'lib/rtrac/ticket.rb', line 7

def initialize(trac_id, logger = nil)
  @logger = logger
  @trac_id = trac_id
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object (protected)



64
65
66
67
68
69
70
# File 'lib/rtrac/ticket.rb', line 64

def method_missing(method)
  if attributes.has_key?(method)
    attributes[method]
  else
    logger.debug "No attribute found for #{method}"
  end
end

Instance Attribute Details

#trac_idObject

Returns the value of attribute trac_id.



5
6
7
# File 'lib/rtrac/ticket.rb', line 5

def trac_id
  @trac_id
end

Class Method Details

.create(title, description, attributes = {}) ⇒ Object

create a new ticket



49
50
51
# File 'lib/rtrac/ticket.rb', line 49

def self.create(title, description, attributes = {})
  send_query('ticket.create', title, description, attributes)
end

.destroy(trac_id) ⇒ Object

delete a ticket forever



54
55
56
# File 'lib/rtrac/ticket.rb', line 54

def self.destroy(trac_id)
  send_query('ticket.delete', trac_id)
end

Instance Method Details

#attributesObject



20
21
22
23
# File 'lib/rtrac/ticket.rb', line 20

def attributes
  extended_attributes = ticket_attributes[3].symbolize_keys!
  {:id => ticket_attributes[0], :created_at => ticket_attributes[1], :updated_at => ticket_attributes[2]}.merge(extended_attributes)
end

#attributes=(attributes) ⇒ Object



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

def attributes=(attributes)
  @ticket_attributes = attributes
end

#created_atObject



12
13
14
# File 'lib/rtrac/ticket.rb', line 12

def created_at
  Time.at(ticket_attributes[1].to_i)
end

#descriptionObject Also known as: body

ticket description



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

def description
  method_missing(:description)
end

#summaryObject Also known as: title

ticket summary



36
37
38
# File 'lib/rtrac/ticket.rb', line 36

def summary
  method_missing(:summary)
end

#to_sObject



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

def to_s
  "#{summary}"
end

#update(comment, attributes = {}) ⇒ Object

update a ticket with a comment and attributes



42
43
44
45
46
# File 'lib/rtrac/ticket.rb', line 42

def update(comment, attributes = {})
  sendable_attributes = attributes
  sendable_attributes.delete(:created_at) && sendable_attributes.delete(:updated_at)
  self.class.send_query('ticket.update', @trac_id, comment, sendable_attributes)
end

#updated_atObject



16
17
18
# File 'lib/rtrac/ticket.rb', line 16

def updated_at
  Time.at(+ticket_attributes[2].to_i)
end