Sha256: 61759d342e482ec4774c8fee522c431ddd0788de41b927895a12caa992eeb321

Contents?: true

Size: 1013 Bytes

Versions: 15

Compression:

Stored size: 1013 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Associations #:nodoc:
    class EmbedsMany < Proxy
      
      def initialize_with_custom_fields(parent, options, target_array = nil)
        if custom_fields?(parent, options.name)
          options = options.clone # 2 parent instances should not share the exact same option instance
          
          custom_fields = parent.send(:"ordered_#{custom_fields_association_name(options.name)}")
        
          klass = options.klass.to_klass_with_custom_fields(custom_fields)
          klass._parent = parent
          klass.association_name = options.name
        
          options.instance_eval <<-EOF
            def klass=(klass); @klass = klass; end
            def klass; @klass || class_name.constantize; end
          EOF
        
          options.klass = klass
        end
        
        initialize_without_custom_fields(parent, options, target_array)
      end
      
      alias_method_chain :initialize, :custom_fields
      
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
custom_fields-1.0.0.beta2 lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
custom_fields-1.0.0.beta lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
custom_fields-0.0.0.1 lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.3.3 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.3.1 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2.9 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2.8 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2.7 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2.6 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2.5 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2.4 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2.3 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2.2 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2.1 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb
locomotive_cms-0.0.2 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/embeds_many.rb