Sha256: 27d7132bfcda0af641288afc50c8469798992a0214c86ee817467e566fbcc108

Contents?: true

Size: 654 Bytes

Versions: 3

Compression:

Stored size: 654 Bytes

Contents

require 'ripple/associations'

module Ripple
  module Associations
    module Many
      include Instantiators

      def to_ary
        load_target
        Array === target ? target.to_ary : Array.wrap(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

3 entries across 3 versions & 3 rubygems

Version Path
wyngle-ripple-0.1.0 lib/ripple/associations/many.rb
better-ripple-1.0.0 lib/ripple/associations/many.rb
ripple-1.0.0.beta2 lib/ripple/associations/many.rb