class ActiveBugzilla::Bug

Public Class Methods

fields() click to toggle source
# File lib/active_bugzilla/bug.rb, line 78
def self.fields
  @fields ||= Field.instantiate_from_raw_data(fetch_fields)
end
find(options = {}) click to toggle source
# File lib/active_bugzilla/bug.rb, line 82
def self.find(options = {})
  options[:include_fields] ||= []
  options[:include_fields] << :id unless options[:include_fields].include?(:id)

  fields_to_include = options[:include_fields].dup

  search(options).collect do |bug_hash|
    fields_to_include.each do |field|
      bug_hash[field] = nil unless bug_hash.key?(field)
      bug_hash[field] = flags_from_raw_flags_data(bug_hash[field]) if field == :flags
    end
    Bug.new(bug_hash)
  end
end
new(attributes = {}) click to toggle source
# File lib/active_bugzilla/bug.rb, line 16
def initialize(attributes = {})
  attributes.each do |key, value|
    next unless attribute_names.include?(key)
    ivar_key = "@#{key}"
    instance_variable_set(ivar_key, value)
  end if attributes
end

Public Instance Methods

add_comment(comment, is_private = false) click to toggle source
# File lib/active_bugzilla/bug.rb, line 73
def add_comment(comment, is_private = false)
  _comment_id = service.add_comment(@id, comment, :is_private => is_private)
  reload
end
comments() click to toggle source
# File lib/active_bugzilla/bug.rb, line 69
def comments
  @comments ||= Comment.instantiate_from_raw_data(raw_comments)
end
keywords_value(value) click to toggle source
# File lib/active_bugzilla/bug.rb, line 39
def keywords_value(value)
  # Default subcommand to keywords_set to simplify API
  # and support user supplied Hash.
  return HashWithIndifferentAccess.new(value) if value.is_a?(Hash)
  HashWithIndifferentAccess.new("keywords_set" => value)
end
reload() click to toggle source
# File lib/active_bugzilla/bug.rb, line 31
def reload
  raw_reset
  reset_instance_variables
  reset_flags
  @comments = Comment.instantiate_from_raw_data(raw_comments)
  self
end
save() click to toggle source
# File lib/active_bugzilla/bug.rb, line 24
def save
  return if changes.empty?
  update_attributes(changed_attribute_hash)
  @changed_attributes.clear
  reload
end
update_attribute(key, value) click to toggle source
# File lib/active_bugzilla/bug.rb, line 65
def update_attribute(key, value)
  update_attributes(key => value)
end
update_attributes(attributes) click to toggle source
# File lib/active_bugzilla/bug.rb, line 46
def update_attributes(attributes)
  attributes.delete(:id)

  attributes.each do |name, value|
    symbolized_name = name.to_sym
    raise "Unknown Attribute #{name}" unless attribute_names.include?(symbolized_name)
    value = keywords_value(value) if symbolized_name == :keywords
    public_send("#{name}=", value)
    if symbolized_name == :flags
      attributes[name] = flags_raw_updates
    else
      attributes[name] = value if symbolized_name == :keywords
      @changed_attributes.delete(symbolized_name)
    end
  end

  raw_update(attributes) unless attributes.empty?
end

Private Instance Methods

changed_attribute_hash() click to toggle source
# File lib/active_bugzilla/bug.rb, line 107
def changed_attribute_hash
  hash = {}
  changes.each do |key, values|
    _value_from, value_to = values
    hash[key.to_sym] = value_to
  end
  hash
end
reset_instance_variables() click to toggle source
# File lib/active_bugzilla/bug.rb, line 99
def reset_instance_variables
  attribute_names do |name|
    next if name == :id
    ivar_name = "@#{name}"
    instance_variable_set(ivar_name, raw_attribute(name))
  end
end