lib/zendesk_api/association.rb in zendesk_api-1.4.2 vs lib/zendesk_api/association.rb in zendesk_api-1.4.3
- old
+ new
@@ -32,11 +32,12 @@
instance = args.first
namespace = @options[:class].to_s.split("::")
namespace[-1] = @options[:class].resource_path
- %w(ZendeskAPI Voice).each { |ns| namespace.delete(ns) }
+ # Remove components without path information
+ ignorable_namespace_strings.each { |ns| namespace.delete(ns) }
has_parent = namespace.size > 1 || (options[:with_parent] && @options.parent)
if has_parent
parent_class = @options.parent ? @options.parent.class : ZendeskAPI.const_get(ZendeskAPI::Helpers.modulize_string(namespace[0]))
parent_namespace = build_parent_namespace(parent_class, instance, options, original_options)
@@ -68,9 +69,14 @@
end
end
end
private
+
+ # @return [Array<String>] ['ZendeskAPI', 'Voice', etc.. ]
+ def ignorable_namespace_strings
+ ZendeskAPI::DataNamespace.descendants.map { |klass| klass.to_s.split('::') }.flatten.uniq
+ end
def _side_load(resource, side_loads)
side_loads.map! do |side_load|
resource.send(:wrap_resource, side_load, options)
end