Sha256: bb89bbc045d488ee9a7eca461ed33b5c601adf8f189feba13cec1cd9097b5b12

Contents?: true

Size: 580 Bytes

Versions: 5

Compression:

Stored size: 580 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, options = {})

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

  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
acts_as_api-0.4.3 lib/acts_as_api/array.rb
acts_as_api_sequel-0.0.1 lib/acts_as_api/array.rb
acts_as_api-0.4.2 lib/acts_as_api/array.rb
acts_as_api-0.4.1 lib/acts_as_api/array.rb
acts_as_api-0.4 lib/acts_as_api/array.rb