module Decanter::CollectionDetection::ClassMethods

Public Instance Methods

decant(args, **options) click to toggle source
Calls superclass method
# 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

Private Instance Methods

collection?(args, collection_option = nil) click to toggle source

leveraging the approach used in the [fast JSON API gem](github.com/Netflix/fast_jsonapi#collection-serialization)

# 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