Sha256: fe2b18efd155c99502a1d421aaa4d26fff1aa3d7d0aa7847700f5e62fd1dfe43
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
# encoding: utf-8 module Mongoid # :nodoc: module Relations #:nodoc: # Superclass for all builder objects. Builders are responsible for either # looking up a relation's target from the database, or creating them from a # supplied attributes hash. class Builder attr_reader :metadata, :object, :loading # Instantiate the new builder for a relation. # # @example Create the builder. # Builder.new(metadata, { :field => "value }) # # @param [ Metdata ] metadata The metadata for the relation. # @param [ Hash, BSON::ObjectId ] object The attributes to build from or # id to query with. # # @since 2.0.0.rc.1 def initialize(metadata, object, loading = false) @metadata, @object = metadata, object @loading = loading end protected # Do we need to perform a database query? It will be so if the object we # have is not a document. # # @example Should we query the database? # builder.query? # # @return [ true, false ] Whether a database query should happen. # # @since 2.0.0.rc.1 def query? return true unless object.respond_to?(:to_a) obj = object.to_a.first !obj.respond_to?(:attributes) && !obj.nil? end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongoid-2.1.0 | lib/mongoid/relations/builder.rb |