Sha256: e630e9138f4597d9df1798da79508ac7d8ca91684f30dd97f23d133e9167b767

Contents?: true

Size: 1.27 KB

Versions: 163

Compression:

Stored size: 1.27 KB

Contents

# encoding: utf-8
module Mongoid # :nodoc:
  module Relations #:nodoc:
    module Cascading #:nodoc:
      class Destroy

        attr_accessor :document, :relation, :metadata

        # Initialize the new cascade strategy, which will set up the relation
        # and the metadata.
        #
        # @example Instantiate the strategy
        #   Strategy.new(document, metadata)
        #
        # @param [ Document ] document The document to cascade from.
        # @param [ Metadata ] metadata The relation's metadata.
        #
        # @return [ Strategy ] The new strategy.
        def initialize(document, metadata)
          @document, @metadata = document, metadata
          @relation = document.send(metadata.name)
        end

        # Execute the cascading deletion for the relation if it already exists.
        # This should be optimized in the future potentially not to load all
        # objects from the db.
        #
        # @example Perform the cascading destroy.
        #   strategy.cascade
        def cascade
          if relation
            if relation.is_a?(Enumerable)
              relation.entries
              relation.each { |doc| doc.destroy }
            else
              relation.destroy
            end
          end
        end
      end
    end
  end
end

Version data entries

163 entries across 71 versions & 3 rubygems

Version Path
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/cascading/destroy.rb
classiccms-0.5.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/cascading/destroy.rb