Module: ActiveBugzilla::Bug::ServiceManagement::ClassMethods

Defined in:
lib/active_bugzilla/bug/service_management.rb

Instance Method Summary collapse

Instance Method Details

#attribute_namesObject



59
60
61
# File 'lib/active_bugzilla/bug/service_management.rb', line 59

def attribute_names
  @attribute_names ||= attributes_xmlrpc_map.keys.sort_by { |sym| sym.to_s }
end

#attributes_xmlrpc_mapObject



18
19
20
21
22
23
24
# File 'lib/active_bugzilla/bug/service_management.rb', line 18

def attributes_xmlrpc_map
  @attributes_xmlrpc_map ||= begin
    hash = generate_xmlrpc_map
    define_attributes(hash.keys)
    hash
  end
end

#default_service_attributesObject



30
31
32
# File 'lib/active_bugzilla/bug/service_management.rb', line 30

def default_service_attributes
  attributes_xmlrpc_map.values - [:comments]
end

#normalize_attributes_from_service(hash) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/active_bugzilla/bug/service_management.rb', line 48

def normalize_attributes_from_service(hash)
  attributes_xmlrpc_map.each do |bug_key, xmlrpc_key|
    next unless hash.key?(xmlrpc_key.to_s)
    value = hash.delete(xmlrpc_key.to_s)
    value = normalize_timestamp(value) if xmlrpc_timestamps.include?(xmlrpc_key)
    hash[bug_key] = value
  end

  hash
end

#normalize_attributes_to_service(hash) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_bugzilla/bug/service_management.rb', line 34

def normalize_attributes_to_service(hash)
  attributes_xmlrpc_map.each do |bug_key, xmlrpc_key|
    bug_key    = bug_key.to_sym
    xmlrpc_key = xmlrpc_key.to_sym
    next if bug_key == xmlrpc_key
    hash[xmlrpc_key] = hash.delete(bug_key)
  end

  hash[:include_fields] = normalize_include_fields_to_service(hash[:include_fields]) if hash.key?(:include_fields)

  hash.delete_if { |k, v| v.nil? }
  hash
end

#search(options = {}) ⇒ Object



63
64
65
66
67
68
# File 'lib/active_bugzilla/bug/service_management.rb', line 63

def search(options = {})
  options = normalize_attributes_to_service(options)
  service.search(options).collect do |bug_hash|
    normalize_attributes_from_service(bug_hash)
  end
end

#xmlrpc_timestampsObject



26
27
28
# File 'lib/active_bugzilla/bug/service_management.rb', line 26

def xmlrpc_timestamps
  @xmlrpc_timestamps ||= fields.select(&:timestamp?).collect { |field| field.name.to_sym }
end