Sha256: 5d2f2ddf145165a3a8b0df276347ce8c8ab135ab11864bdea323d6d63645dcec

Contents?: true

Size: 978 Bytes

Versions: 193

Compression:

Stored size: 978 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Criterion #:nodoc:

    # This module defines criteria behavior for creating documents in the
    # database for specified conditions.
    module Creational

      # Create a document in the database given the selector and return it.
      # Complex criteria, such as $in and $or operations will get ignored.
      #
      # @example Create the document.
      #   Person.where(:title => "Sir").create
      #
      # @example Create with selectors getting ignored.
      #   Person.where(:age.gt => 5).create
      #
      # @return [ Document ] A newly created document.
      #
      # @since 2.0.0.rc.1
      def create(attrs = {})
        klass.create(
          selector.inject(attrs) do |hash, (key, value)|
            hash.tap do |attrs|
              unless key.to_s =~ /\$/ || value.is_a?(Hash)
                attrs[key] = value
              end
            end
          end
        )
      end
    end
  end
end

Version data entries

193 entries across 101 versions & 5 rubygems

Version Path
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/criterion/creational.rb
classiccms-0.5.15 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/criterion/creational.rb
classiccms-0.5.15 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/criterion/creational.rb
classiccms-0.5.15 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/criterion/creational.rb
classiccms-0.5.14 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/criterion/creational.rb
classiccms-0.5.14 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/criterion/creational.rb
classiccms-0.5.14 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/criterion/creational.rb
classiccms-0.5.13 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/criterion/creational.rb
classiccms-0.5.13 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/criterion/creational.rb
classiccms-0.5.13 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/criterion/creational.rb
mongoid-2.5.0 lib/mongoid/criterion/creational.rb
classiccms-0.5.12 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/criterion/creational.rb
classiccms-0.5.12 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/criterion/creational.rb
classiccms-0.5.12 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/criterion/creational.rb
classiccms-0.5.11 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/criterion/creational.rb
classiccms-0.5.11 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/criterion/creational.rb
classiccms-0.5.11 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/criterion/creational.rb
classiccms-0.5.10 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/criterion/creational.rb
classiccms-0.5.10 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/criterion/creational.rb
classiccms-0.5.10 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/criterion/creational.rb