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, data, values = nil, options = nil) ⇒ Result

Init takes a Mongo::Operation::Result



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

def initialize(result, data, values = nil, options = nil)
  self.result = result
  self.data = data
  self.values = values
  self.options = options
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



30
31
32
33
# File 'lib/easymongo/result.rb', line 30

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

Instance Attribute Details

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#resultObject

Returns the value of attribute result.



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

def result
  @result
end

#valuesObject

Returns the value of attribute values.



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

def values
  @values
end

Instance Method Details

#bson_idObject

Get the id as BSON::ObjectId



15
16
17
# File 'lib/easymongo/result.rb', line 15

def bson_id
  result.upserted_id || data['_id']
end

#dateObject

Creation date



25
26
27
# File 'lib/easymongo/result.rb', line 25

def date
  bson_id ? bson_id.generation_time : nil
end

#idObject

Get the id if available



20
21
22
# File 'lib/easymongo/result.rb', line 20

def id
  bson_id ? bson_id.to_s : nil
end