Sha256: 683cef8f415e8ceddb9eff29e834520f1c5167295edac0f647ea9d81b3864eb7

Contents?: true

Size: 709 Bytes

Versions: 2

Compression:

Stored size: 709 Bytes

Contents

# frozen_string_literal: true

module Contentful
  module Management
    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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contentful-management-3.10.0 lib/contentful/management/resource/array_like.rb
contentful-management-3.9.0 lib/contentful/management/resource/array_like.rb