Sha256: f1c5c7f10fa1228df7e352e1d7b2dd2a0ab3561b91f75c31ef82c199df10cac1

Contents?: true

Size: 599 Bytes

Versions: 5

Compression:

Stored size: 599 Bytes

Contents

module Contentful
  module Resource
    # Useful methods for array-like resources that can be included if an
    # :items property exists
    module ArrayLike
      include Enumerable

      # Returns true for array-like resources
      def array?
        true
      end

      # Delegates to items#each
      def each_item(&block)
        items.each(&block)
      end
      alias each each_item

      # Delegates to items#empty?
      def empty?
        items.empty?
      end

      # Delegetes to items#size
      def size
        items.size
      end
      alias length size

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contentful-0.3.4 lib/contentful/resource/array_like.rb
contentful-0.3.3 lib/contentful/resource/array_like.rb
contentful-0.3.2 lib/contentful/resource/array_like.rb
contentful-0.3.1 lib/contentful/resource/array_like.rb
contentful-0.3.0 lib/contentful/resource/array_like.rb