module MongoModel::AttributeMethods::Nested::ClassMethods

Public Instance Methods

accepts_nested_attributes_for(*attr_names) click to toggle source
# File lib/mongomodel/concerns/attribute_methods/nested.rb, line 12
        def accepts_nested_attributes_for(*attr_names)
          options = attr_names.extract_options!

          attr_names.each do |attr_name|
            type = property_type(attr_name)

            nested_attributes_options = self.nested_attributes_options.dup
            nested_attributes_options[attr_name.to_sym] = options
            self.nested_attributes_options = nested_attributes_options

            class_eval <<-EORUBY, __FILE__, __LINE__ + 1
              if method_defined?(:#{attr_name}_attributes=)
                remove_method(:#{attr_name}_attributes=)
              end

              def #{attr_name}_attributes=(attributes)
                assign_nested_attributes_for_#{type}(:#{attr_name}, attributes)
              end
            EORUBY
          end
        end

Private Instance Methods

property_type(attr_name) click to toggle source
# File lib/mongomodel/concerns/attribute_methods/nested.rb, line 35
def property_type(attr_name)
  if property = properties[attr_name]
    property.type <= Array ? :collection : :property
  elsif association = associations[attr_name]
    association.collection? ? :association_collection : :association
  end
end