Sha256: 975bf7d886a7d492b5a9eabaa7327438c29461dfd3b778464890da3b4389ef96

Contents?: true

Size: 811 Bytes

Versions: 1

Compression:

Stored size: 811 Bytes

Contents

require 'ripple/associations/proxy'
require 'ripple/validations/associated_validator'

module Ripple
  module Associations
    module Embedded

      def initialize(*args)
        super
        lazy_load_validates_associated
      end

      protected

      def lazy_load_validates_associated
        return if @owner.class.validators_on(@reflection.name).any? {|v| Ripple::Validations::AssociatedValidator === v}
        @owner.class.validates @reflection.name, :associated => true
      end

      def assign_references(docs)
        Array(docs).each do |doc|
          next unless doc.respond_to?(:_parent_document=)
          doc._parent_document = owner
        end
      end

      def instantiate_target(*args)
        doc = super
        assign_references(doc)
        doc
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ripple-1.0.0.beta lib/ripple/associations/embedded.rb