Sha256: e961212674c5a836ea891462701f355eb98e3597dfaa8da9b139b32d0bee5745

Contents?: true

Size: 608 Bytes

Versions: 6

Compression:

Stored size: 608 Bytes

Contents

module Easymongo
  class Result

    attr_reader :result

    # Init takes a Mongo::Operation::Result
    def initialize(result)
      @result = result
    end

    # Get the id as BSON::ObjectId
    def bson_id
      result.upserted_id rescue nil
    end

    # Get the id if available
    def id
      bson_id ? bson_id.to_s : nil
    end

    # Creation date
    def date
      bson_id ? bson_id.generation_time : nil
    end

    # For the mongo operation result
    def method_missing(name, *args, &block)
      return result.send(name, *args) if result.respond_to?(name)
      super
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
easymongo-0.0.9 lib/easymongo/result.rb
easymongo-0.0.8 lib/easymongo/result.rb
easymongo-0.0.7 lib/easymongo/result.rb
easymongo-0.0.6 lib/easymongo/result.rb
easymongo-0.0.5 lib/easymongo/result.rb
easymongo-0.0.4 lib/easymongo/result.rb