Sha256: 455dd7c3be937b69b0b7c91d1889e551eabaeb74eba3f762ab13f827f962bd03

Contents?: true

Size: 558 Bytes

Versions: 6

Compression:

Stored size: 558 Bytes

Contents

# The standard ruby Array class is extended by one instance method.
class Array

  # Neccessary to render an Array of models, e.g. the result of a search.
  #
  # The Array checks all its items if they respond to the +as_api_response+ method.
  # If they do, the result of this method will be collected.
  # If they don't, the item itself will be collected.
  def as_api_response(api_template)

    collect do |item|
      if item.respond_to?(:as_api_response)
        item.as_api_response(api_template)
      else
        item
      end
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
acts_as_api-0.3.11 lib/acts_as_api/array.rb
acts_as_api-0.3.10 lib/acts_as_api/array.rb
acts_as_api-0.3.9 lib/acts_as_api/array.rb
acts_as_api-0.3.8 lib/acts_as_api/array.rb
acts_as_api-0.3.7 lib/acts_as_api/array.rb
acts_as_api-0.3.6 lib/acts_as_api/array.rb