Class: Bicho::Bug

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

Overview

A single bug inside a bugzilla instance.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data) ⇒ Bug

Normally you will not use this constructor as bugs will be constructed by a query result


54
55
56
57
# File 'lib/bicho/bug.rb', line 54

def initialize(client, data)
  @client = client
  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *_args) ⇒ Object


59
60
61
62
# File 'lib/bicho/bug.rb', line 59

def method_missing(method_name, *_args)
  return super unless @data.key?(method_name.to_s)
  self[method_name]
end

Class Method Details

.where(conditions = {}) ⇒ Array

ActiveRecord like interface

Requires Bicho.client to be set

alias

Examples:

Searching for bugs

Bug.where(:summary => "crash").each do |bug|
  #...do something with bug
end

See Also:


45
46
47
# File 'lib/bicho/bug.rb', line 45

def self.where(conditions = {})
  Query.new(conditions)
end

Instance Method Details

#[](name, subname = nil) ⇒ Object


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

def [](name, subname = nil)
  value = @data[name.to_s]
  value = value[subname.to_s] if subname # for 'internals' properties
  if value.is_a?(XMLRPC::DateTime)
    value.to_time
  else
    value
  end
end

#add_attachment(summary, file, **kwargs) ⇒ ID

Add an attachment to the bug For the params description, see the Client.add_attachment method.


108
109
110
# File 'lib/bicho/bug.rb', line 108

def add_attachment(summary, file, **kwargs)
  @client.add_attachment(summary, file, id, **kwargs).first
end

#attachmentsArray<Attachment>


100
101
102
# File 'lib/bicho/bug.rb', line 100

def attachments
  @client.get_attachments(id)
end

#format(format_string) ⇒ Object


113
114
115
116
# File 'lib/bicho/bug.rb', line 113

def format(format_string)
  sym_data = Hash[@data.to_a.map { |k, v| [k.to_sym, v] }]
  Kernel.format(format_string, sym_data)
end

#historyHistory


95
96
97
# File 'lib/bicho/bug.rb', line 95

def history
  @client.get_history(id).first
end

#idObject


68
69
70
71
72
# File 'lib/bicho/bug.rb', line 68

def id
  # we define id to not get the deprecated
  # warning of object_id
  @data['id']
end

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean


64
65
66
# File 'lib/bicho/bug.rb', line 64

def respond_to_missing?(method_name, _include_private = false)
  @data.key?(method_name.to_s) || super
end

#to_hHash


119
120
121
# File 'lib/bicho/bug.rb', line 119

def to_h
  Hash[@data.to_a.map { |k, _| [k.to_sym, self[k.to_sym]] }]
end

#to_sObject


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

def to_s
  "##{id} - #{summary} (#{url})"
end

#urlObject

URL where the bug can be viewed Example: bugs.foo.com/2345


90
91
92
# File 'lib/bicho/bug.rb', line 90

def url
  "#{@client.site_url}/#{id}"
end