Class: Easymongo::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/easymongo/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Result

Init takes a Mongo::Operation::Result



7
8
9
# File 'lib/easymongo/result.rb', line 7

def initialize(result)
  @result = result
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

For the mongo operation result



27
28
29
30
# File 'lib/easymongo/result.rb', line 27

def method_missing(name, *args, &block)
  return result.send(name, *args) if result.respond_to?(name)
  super
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/easymongo/result.rb', line 4

def result
  @result
end

Instance Method Details

#bson_idObject

Get the id as BSON::ObjectId



12
13
14
# File 'lib/easymongo/result.rb', line 12

def bson_id
  result.upserted_id rescue nil
end

#dateObject

Creation date



22
23
24
# File 'lib/easymongo/result.rb', line 22

def date
  bson_id ? bson_id.generation_time : nil
end

#idObject

Get the id if available



17
18
19
# File 'lib/easymongo/result.rb', line 17

def id
  bson_id ? bson_id.to_s : nil
end