Sha256: 4a75db01f2eda699ec0c909dec21299a4312fb9552d6ac83d861cd49802146bc

Contents?: true

Size: 758 Bytes

Versions: 12

Compression:

Stored size: 758 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
      #
      # @return [true]
      def array?
        true
      end

      # Delegates to items#each
      #
      # @yield [Contentful::Entry, Contentful::Asset]
      def each_item(&block)
        items.each(&block)
      end
      alias each each_item

      # Delegates to items#empty?
      #
      # @return [Boolean]
      def empty?
        items.empty?
      end

      # Delegetes to items#size
      #
      # @return [Number]
      def size
        items.size
      end
      alias length size
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
contentful-1.2.2 lib/contentful/resource/array_like.rb
contentful-1.2.1 lib/contentful/resource/array_like.rb
contentful-1.2.0 lib/contentful/resource/array_like.rb
contentful-1.1.1 lib/contentful/resource/array_like.rb
contentful-1.1.0 lib/contentful/resource/array_like.rb
contentful-1.0.2 lib/contentful/resource/array_like.rb
contentful-1.0.1 lib/contentful/resource/array_like.rb
contentful-1.0.0 lib/contentful/resource/array_like.rb
contentful-0.12.0 lib/contentful/resource/array_like.rb
contentful-0.11.0 lib/contentful/resource/array_like.rb
contentful-0.10.0 lib/contentful/resource/array_like.rb
contentful-0.9.0 lib/contentful/resource/array_like.rb