lib/freshdesk_api/collection.rb in freshdesk_api-0.1.3 vs lib/freshdesk_api/collection.rb in freshdesk_api-0.2.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module FreshdeskAPI
# Represents a collection of resources
class Collection
attr_reader :resources
attr_reader :resource_class
@@ -12,11 +14,11 @@
@client = client
@resource_class = resource
@resource = resource.resource_name
@options = options
- methods = %w{ create find update destroy }
+ methods = %w[create find update destroy]
methods += methods.map { |method| method + '!' }
methods.each do |deferrable|
# Passes arguments and the proper path to the resource class method.
# @param [Hash] options Options or attributes to pass
define_singleton_method deferrable do |*args|
@@ -26,11 +28,10 @@
opts = args.last.is_a?(Hash) ? args.pop : {}
@resource_class.send(deferrable, @client, opts)
end
end
-
end
# The API path to this collection
def path
@resource_class.api_url(@options)
@@ -78,12 +79,9 @@
else
inspect = []
inspect << "options=#{@options.inspect}" if @options.any?
"#{@resource.singularize} collection [#{inspect.join(',')}]"
end
-
end
- alias :inspect :to_s
-
+ alias inspect to_s
end
-
end