Sha256: 600118b0c429d403912e9c82486da07269c506a6cbbf7366d2e5459e5cbd467d

Contents?: true

Size: 930 Bytes

Versions: 12

Compression:

Stored size: 930 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Document
    module InstanceMethods
      
      def parentize_with_custom_fields(object, association_name)
        if association_name.to_s.ends_with?('_custom_fields')
          self.singleton_class.associations = {}
          self.singleton_class.embedded_in object.class.to_s.underscore.to_sym, :inverse_of => association_name
        end
            
        parentize_without_custom_fields(object, association_name)
        
        if self.embedded? && self.instance_variable_get(:"@association_name").nil?
          self.instance_variable_set(:"@association_name", association_name) # weird bug with proxy class
        end
        
        if association_name.to_s.ends_with?('_custom_fields')
          self.send(:set_unique_name!)
          self.send(:set_alias)
        end
      end
      
      alias_method_chain :parentize, :custom_fields
      
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
locomotive_cms-0.0.3.3 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.3.1 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2.9 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2.8 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2.7 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2.6 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2.5 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2.4 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2.3 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2.2 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2.1 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb
locomotive_cms-0.0.2 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/document.rb