lib/mongoid/association/referenced/has_one/nested_builder.rb in mongoid-7.3.5 vs lib/mongoid/association/referenced/has_one/nested_builder.rb in mongoid-7.4.0

- old
+ new

@@ -1,7 +1,6 @@ # frozen_string_literal: true -# encoding: utf-8 module Mongoid module Association module Referenced module NestedAttributes @@ -20,12 +19,10 @@ # document, or a removal of the association. # # @param [ Document ] parent The parent document. # # @return [ Document ] The built document. - # - # @since 2.0.0 def build(parent) return if reject?(parent, attributes) @existing = parent.send(association.name) if update? attributes.delete_id @@ -44,12 +41,10 @@ # One.new(association, attributes) # # @param [ Association ] association The association metadata. # @param [ Hash ] attributes The attributes hash to attempt to set. # @param [ Hash ] options The options defined. - # - # @since 2.0.0 def initialize(association, attributes, options) @attributes = attributes.with_indifferent_access @association = association @options = options @destroy = @attributes.delete(:_destroy) @@ -64,12 +59,10 @@ # # @example Is the id acceptable? # one.acceptable_id? # # @return [ true, false ] If the id part of the logic will allow an update. - # - # @since 2.0.0 def acceptable_id? id = convert_id(existing.class, attributes[:_id]) existing._id == id || id.nil? || (existing._id != id && update_only?) end @@ -77,12 +70,10 @@ # # @example Can the existing object be deleted? # one.delete? # # @return [ true, false ] If the association should be deleted. - # - # @since 2.0.0 def delete? destroyable? && !attributes[:_id].nil? end # Can the existing association potentially be destroyed? @@ -90,35 +81,29 @@ # @example Is the object destroyable? # one.destroyable?({ :_destroy => "1" }) # # @return [ true, false ] If the association can potentially be # destroyed. - # - # @since 2.0.0 def destroyable? [ 1, "1", true, "true" ].include?(destroy) && allow_destroy? end # Is the document to be replaced? # # @example Is the document to be replaced? # one.replace? # # @return [ true, false ] If the document should be replaced. - # - # @since 2.0.0 def replace? !existing && !destroyable? && !attributes.blank? end # Should the document be updated? # # @example Should the document be updated? # one.update? # # @return [ true, false ] If the object should have its attributes updated. - # - # @since 2.0.0 def update? existing && !destroyable? && acceptable_id? end end end