module Decanter::CollectionDetection::ClassMethods
Public Instance Methods
Source
# File lib/decanter/collection_detection.rb, line 8 def decant(args, **options) return super(args) unless collection?(args, options[:is_collection]) args.map { |resource| super(resource) } end
Calls superclass method
Private Instance Methods
Source
# File lib/decanter/collection_detection.rb, line 17 def collection?(args, collection_option = nil) raise(ArgumentError, "#{name}: Unknown collection option value: #{collection_option}") unless [true, false, nil].include? collection_option return collection_option unless collection_option.nil? args.respond_to?(:size) && !args.respond_to?(:each_pair) end
leveraging the approach used in the [fast JSON API gem](github.com/Netflix/fast_jsonapi#collection-serialization)