module ActiveBugzilla::Bug::ServiceManagement::ClassMethods
Public Instance Methods
attribute_names()
click to toggle source
# 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_map()
click to toggle source
# 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_attributes()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
# 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_timestamps()
click to toggle source
# 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
Private Instance Methods
define_attributes(names)
click to toggle source
# File lib/active_bugzilla/bug/service_management.rb, line 94 def define_attributes(names) define_attribute_methods names names.each do |name| next if name.to_s == 'flags' # Flags is a special attribute ivar_name = "@#{name}" define_method(name) do return instance_variable_get(ivar_name) if instance_variable_defined?(ivar_name) instance_variable_set(ivar_name, raw_attribute(name)) end define_method("#{name}=") do |val| public_send("#{name}_will_change!") unless val == instance_variable_get(ivar_name) instance_variable_set(ivar_name, val) end end end
fetch_fields()
click to toggle source
# File lib/active_bugzilla/bug/service_management.rb, line 72 def fetch_fields service.fields end
generate_xmlrpc_map()
click to toggle source
# File lib/active_bugzilla/bug/service_management.rb, line 76 def generate_xmlrpc_map hash = ATTRIBUTES_XMLRPC_RENAMES_MAP fields.each do |field| next if hash.values.include?(field.name) next if field.name.include?(".") attribute_name = field.name attribute_name = attribute_name[3..-1] if attribute_name[0..2] == "cf_" hash[attribute_name.to_sym] = field.name.to_sym end hash end
normalize_include_fields_to_service(include_fields)
click to toggle source
# File lib/active_bugzilla/bug/service_management.rb, line 88 def normalize_include_fields_to_service(include_fields) include_fields.collect do |bug_key| attributes_xmlrpc_map[bug_key] end.uniq.compact end