Sha256: 5eebd3643b98624264138e2b2b104fc5cf3d5559c2b3e411a8f0a9d712acd03c
Contents?: true
Size: 1.25 KB
Versions: 5
Compression:
Stored size: 1.25 KB
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Persistence #:nodoc: # Persistence commands extend from this class to get basic functionality on # initialization. class Command include Mongoid::Safe attr_reader \ :collection, :document, :klass, :options, :selector, :validate # Initialize the persistence +Command+. # # Options: # # document_or_class: The +Document+ or +Class+ to get the collection. # options: Options like validation or safe mode. # selector: Optional selector to use in query. # # Example: # # <tt>DeleteAll.new(Person, { :validate => true }, {})</tt> def initialize(document_or_class, options = {}, selector = {}) if document_or_class.is_a?(Mongoid::Document) @document = document_or_class @collection = @document.embedded? ? @document._root.collection : @document.collection else @klass = document_or_class @collection = @klass.collection end validate = options[:validate] @selector = selector @validate = (validate.nil? ? true : validate) @options = { :safe => safe_mode?(options) } end end end end
Version data entries
5 entries across 5 versions & 1 rubygems