Sha256: 265d6e85c4fafa47b42b66b64ed6d8ae431e22fbe9dbb703827be29b7aa8815e

Contents?: true

Size: 618 Bytes

Versions: 6

Compression:

Stored size: 618 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_method :each, :each_item

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

      # Delegetes to items#size
      def size
        items.size
      end
      alias_method :length, :size
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contentful-0.8.0 lib/contentful/resource/array_like.rb
contentful-0.7.0 lib/contentful/resource/array_like.rb
contentful-0.6.0 lib/contentful/resource/array_like.rb
contentful-0.5.0 lib/contentful/resource/array_like.rb
contentful-0.4.0 lib/contentful/resource/array_like.rb
contentful-0.3.5 lib/contentful/resource/array_like.rb