lib/zendesk_api/collection.rb in zendesk_api-1.9.1 vs lib/zendesk_api/collection.rb in zendesk_api-1.9.2

- old
+ new

@@ -44,13 +44,13 @@ else @fetchable = true end end + # Methods that take a Hash argument methods = %w{create find update destroy} methods += methods.map {|method| method + "!"} - methods += %w{create_many! destroy_many!} methods.each do |deferrable| # Passes arguments and the proper path to the resource class method. # @param [Hash] options Options or attributes to pass define_method deferrable do |*args| unless @resource_class.respond_to?(deferrable) @@ -59,9 +59,25 @@ opts = args.last.is_a?(Hash) ? args.pop : {} opts.merge!(:association => @association) @resource_class.send(deferrable, @client, opts) + end + end + + # Methods that take an Array argument + methods = %w{create_many! destroy_many!} + methods.each do |deferrable| + # Passes arguments and the proper path to the resource class method. + # @param [Array] array arguments + define_method deferrable do |*args| + unless @resource_class.respond_to?(deferrable) + raise NoMethodError.new("undefined method \"#{deferrable}\" for #{@resource_class}", deferrable, args) + end + + array = args.last.is_a?(Array) ? args.pop : [] + + @resource_class.send(deferrable, @client, array, @association) end end # Convenience method to build a new resource and # add it to the collection. Fetches the collection as well.