Sha256: 9d972f2168e683da9559104088c8f268490bf0dccf6081e72073908cdc802795

Contents?: true

Size: 649 Bytes

Versions: 2

Compression:

Stored size: 649 Bytes

Contents

require 'ripple/associations'

module Ripple
  module Associations
    module Many
      include Instantiators

      def to_ary
        load_target
        Array === target ? target.to_ary : Array(target)
      end

      def count
        load_target
        target.size
      end

      def reset
        super
        @target = []
      end

      def <<(value)
        raise NotImplementedError
      end

      alias_method :push, :<<
      alias_method :concat, :<<

      protected
      def instantiate_target(instantiator, attrs={})
        doc = klass.send(instantiator, attrs)
        self << doc
        doc
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
seomoz-ripple-1.0.0.pre lib/ripple/associations/many.rb
ripple-1.0.0.beta lib/ripple/associations/many.rb