Sha256: 5572c4fd793a2f271ccbf40fe215ed77d554dd2bb45a21394af26651e9501573

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8
module Mongoid
  module Relations
    module Cascading
      class Restrict

        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 delete.
        #   strategy.cascade
        def cascade
          raise Errors::DeleteRestriction.new(document, metadata.name) unless relation.blank?
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mongoid-3.0.5 lib/mongoid/relations/cascading/restrict.rb
mongoid-3.0.4 lib/mongoid/relations/cascading/restrict.rb
mongoid-3.0.3 lib/mongoid/relations/cascading/restrict.rb
mongoid-3.0.2 lib/mongoid/relations/cascading/restrict.rb
mongoid-3.0.1 lib/mongoid/relations/cascading/restrict.rb
mongoid-3.0.0 lib/mongoid/relations/cascading/restrict.rb
mongoid-3.0.0.rc lib/mongoid/relations/cascading/restrict.rb