Sha256: e2ad8a97e38a08856ae0502e7979591a987cee80297a4c1dd4d868c68e3a6bab

Contents?: true

Size: 578 Bytes

Versions: 6

Compression:

Stored size: 578 Bytes

Contents

# The standard ruby Array class is extended by one 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

    sub_items = []

    each do |item|
      if item.respond_to?(:as_api_response)
        sub_items << item.as_api_response
      else
        sub_items << item
      end
    end

    sub_items

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
acts_as_api-0.1.10 lib/acts_as_api/array.rb
acts_as_api-0.1.7 lib/acts_as_api/array.rb
acts_as_api-0.1.4 lib/acts_as_api/array.rb
acts_as_api-0.0.3 lib/acts_as_api/array.rb
acts_as_api-0.0.2 lib/acts_as_api/array.rb
acts_as_api-0.0.1 lib/acts_as_api/array.rb