Sha256: 5019b629f3b89361ec3d06b3d2ad056511baaaa3e98b0dc274365618ab6c84fc

Contents?: true

Size: 918 Bytes

Versions: 4

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true

module MicroMicro
  module Collections
    class BaseCollection
      extend Forwardable

      include Enumerable

      def_delegators :members, :[], :each, :last, :length, :split

      # @param members [Array<MicroMicro::Item, MicroMicro::Property, MicroMicro::Relationship>]
      def initialize(members = [])
        members.each { |member| push(member) }
      end

      # @return [String]
      #
      # :nocov:
      def inspect
        "#<#{self.class}:#{format('%#0x', object_id)} " \
          "count: #{count}, " \
          "members: #{members.inspect}>"
      end
      # :nocov:

      # @param member [MicroMicro::Item, MicroMicro::Property, MicroMicro::Relationship]
      def push(member)
        members << member

        member.collection = self
      end

      alias << push

      private

      def members
        @members ||= []
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
micromicro-5.0.0 lib/micro_micro/collections/base_collection.rb
micromicro-4.0.0 lib/micro_micro/collections/base_collection.rb
micromicro-3.1.0 lib/micro_micro/collections/base_collection.rb
micromicro-3.0.0 lib/micro_micro/collections/base_collection.rb