Sha256: a0fd28abbe3db6260ecd019d25f45c5fbc4c003f03a1c174de8a46fc5347c1f7

Contents?: true

Size: 933 Bytes

Versions: 36

Compression:

Stored size: 933 Bytes

Contents

module Contentful
  # 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

    # Delegates to items#[]
    #
    # @return [Contentful::Entry, Contentful::Asset]
    def [](index)
      items[index]
    end

    # Delegates to items#last
    #
    # @return [Contentful::Entry, Contentful::Asset]
    def last
      items.last
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
contentful-2.15.3 lib/contentful/array_like.rb
contentful-2.15.2 lib/contentful/array_like.rb
contentful-2.15.1 lib/contentful/array_like.rb
contentful-2.15.0 lib/contentful/array_like.rb
contentful-2.14.0 lib/contentful/array_like.rb
contentful-2.13.3 lib/contentful/array_like.rb
contentful-2.13.2 lib/contentful/array_like.rb
contentful-2.13.1 lib/contentful/array_like.rb
contentful-2.13.0 lib/contentful/array_like.rb
contentful-2.12.0 lib/contentful/array_like.rb
contentful-2.11.1 lib/contentful/array_like.rb
contentful-2.11.0 lib/contentful/array_like.rb
contentful-2.10.1 lib/contentful/array_like.rb
contentful-2.10.0 lib/contentful/array_like.rb
contentful-2.9.4 lib/contentful/array_like.rb
contentful-2.9.3 lib/contentful/array_like.rb
contentful-2.9.2 lib/contentful/array_like.rb
contentful-2.9.1 lib/contentful/array_like.rb
contentful-2.8.1 lib/contentful/array_like.rb
contentful-2.8.0 lib/contentful/array_like.rb