Exception: Mongoid::Errors::DocumentNotFound
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
MongoidError ,
StandardError
|
|
Instance Chain:
self,
MongoidError ,
StandardError
|
|
Inherits: |
Mongoid::Errors::MongoidError
|
Defined in: | lib/mongoid/errors/document_not_found.rb |
Overview
Raised when querying the database for a document by a specific id or by set of attributes which does not exist. If multiple ids were passed then it will display all of those.
Constant Summary
MongoidError
- Inherited
Class Method Summary
-
.new(klass, params, unmatched = nil) ⇒ DocumentNotFound
constructor
Create the new error.
Instance Attribute Summary
Instance Method Summary
-
#message_key(params, unmatched) ⇒ String
private
Create the problem.
-
#missing(unmatched) ⇒ String
private
Get the string to display the document params that were unmatched.
-
#searched(params) ⇒ String
private
Get the string to display the document params that were searched for.
-
#shard_key(unmatched) ⇒ String
private
Get the shard key from the unmatched hash.
-
#total(params) ⇒ Integer
private
Get the total number of expected documents.
MongoidError
- Inherited
#compose_message | Compose the message. |
#translate | Given the key of the specific error and the options hash, translate the message. |
#translate_problem | Create the problem. |
#translate_resolution | Create the resolution. |
#translate_summary | Create the summary. |
Constructor Details
.new(klass, params, unmatched = nil) ⇒ DocumentNotFound
Create the new error.
# File 'lib/mongoid/errors/document_not_found.rb', line 26
def initialize(klass, params, unmatched = nil) if !unmatched && !params.is_a?(Hash) unmatched = Array(params) if params end @klass, @params = klass, params super( ( (params, unmatched), { klass: klass.name, searched: searched(params), attributes: params, total: total(params), missing: missing(unmatched), shard_key: shard_key(unmatched) } ) ) end
Instance Attribute Details
#klass (readonly)
[ GitHub ]# File 'lib/mongoid/errors/document_not_found.rb', line 12
attr_reader :klass, :params
#params (readonly)
[ GitHub ]# File 'lib/mongoid/errors/document_not_found.rb', line 12
attr_reader :klass, :params
Instance Method Details
#message_key(params, unmatched) ⇒ String (private)
Create the problem.
# File 'lib/mongoid/errors/document_not_found.rb', line 101
def (params, unmatched) if !params && !unmatched "no_documents_found" elsif Hash === params "document_with_attributes_not_found" elsif Hash === unmatched && unmatched.size >= 2 "document_with_shard_key_not_found" else "document_not_found" end end
#missing(unmatched) ⇒ String (private)
Get the string to display the document params that were unmatched.
#searched(params) ⇒ String (private)
Get the string to display the document params that were searched for.
#shard_key(unmatched) ⇒ String (private)
Get the shard key from the unmatched hash.
# File 'lib/mongoid/errors/document_not_found.rb', line 116
def shard_key(unmatched) if Hash === unmatched h = unmatched.dup h.delete("_id") h.delete(:_id) h.map{|k,v| "#{k}: #{v}" }.join(", ") end end
#total(params) ⇒ Integer (private)
Get the total number of expected documents.