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

Parameters:

  • client (Bicho::Client)

    client where this bug gets its data

  • data (Hash)

    retrieved data for this bug



56
57
58
59
# File 'lib/bicho/bug.rb', line 56

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



61
62
63
64
# File 'lib/bicho/bug.rb', line 61

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

Parameters:

  • conds (Hash)

    the conditions for the query.

Returns:

  • (Array)

See Also:



47
48
49
# File 'lib/bicho/bug.rb', line 47

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

Instance Method Details

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



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

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.

Returns:

  • (ID)

    of the new attachment



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

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

#attachmentsArray<Attachment>

Returns attachments for this bug.

Returns:

  • (Array<Attachment>)

    attachments for this bug



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

def attachments
  @client.get_attachments(id)
end

#format(format_string) ⇒ Object

Parameters:

  • format_string

    For Kernel#sprintf; named params supplied by the bug



125
126
127
128
# File 'lib/bicho/bug.rb', line 125

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

Returns history for this bug.

Returns:

  • (History)

    history for this bug



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

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

#idObject



70
71
72
73
74
# File 'lib/bicho/bug.rb', line 70

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

#reopen!(comment, is_private = false) ⇒ Object

reopen a closed bug

Parameters:

  • a

    String comment to add

  • @optional

    a Boolean indicator if the new comment should be private (defaults to ‘false’)



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

def reopen!(comment, is_private = false)
  @client.update_bug(id, status: 'REOPENED', comment: { body: comment.to_s, is_private: is_private.to_b })
end

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

Returns:

  • (Boolean)


66
67
68
# File 'lib/bicho/bug.rb', line 66

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

#to_hHash

Returns:

  • (Hash)


131
132
133
# File 'lib/bicho/bug.rb', line 131

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

#to_sObject



76
77
78
# File 'lib/bicho/bug.rb', line 76

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

#urlObject

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



102
103
104
# File 'lib/bicho/bug.rb', line 102

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