Parent

Included Modules

Class/Module Index [+]

Quicksearch

Moped::BSON::ObjectId

Public Class Methods

__bson_load__(io) click to toggle source
# File lib/moped/bson/object_id.rb, line 77
def __bson_load__(io)
  from_data(io.read(12))
end
from_data(data) click to toggle source
# File lib/moped/bson/object_id.rb, line 23
def from_data(data)
  id = allocate
  id.send(:data=, data)
  id
end
from_string(string) click to toggle source
# File lib/moped/bson/object_id.rb, line 10
def from_string(string)
  raise Errors::InvalidObjectId.new(string) unless legal?(string)
  from_data [string].pack("H*")
end
from_time(time) click to toggle source
# File lib/moped/bson/object_id.rb, line 15
def from_time(time)
  from_data [time.to_i].pack("Nx8")
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/moped/bson/object_id.rb, line 48
def <=>(other)
  data <=> other.data
end
==(other) click to toggle source
# File lib/moped/bson/object_id.rb, line 43
def ==(other)
  BSON::ObjectId === other && data == other.data
end
Also aliased as: eql?
===(other) click to toggle source
# File lib/moped/bson/object_id.rb, line 30
def ===(other)
  return to_str === other.to_str if other.respond_to?(:to_str)
  super
end
__bson_dump__(io, key) click to toggle source
# File lib/moped/bson/object_id.rb, line 82
def __bson_dump__(io, key)
  io << Types::OBJECT_ID
  io << key.to_bson_cstring
  io << data
end
data() click to toggle source
# File lib/moped/bson/object_id.rb, line 35
def data
  # If @data is defined, then we know we've been loaded in some
  # non-standard way, so we attempt to repair the data.
  repair! @data if defined? @data

  @raw_data ||= @@generator.next
end
eql?(other) click to toggle source
Alias for: ==
generation_time() click to toggle source

Return the UTC time at which this ObjectId was generated. This may be used instread of a created_at timestamp since this information is always encoded in the object id.

# File lib/moped/bson/object_id.rb, line 72
def generation_time
  Time.at(data.unpack("N")[0]).utc
end
hash() click to toggle source
# File lib/moped/bson/object_id.rb, line 52
def hash
  data.hash
end
inspect() click to toggle source
# File lib/moped/bson/object_id.rb, line 61
def inspect
  to_s.inspect
end
marshal_dump() click to toggle source

@private

# File lib/moped/bson/object_id.rb, line 122
def marshal_dump
  data
end
marshal_load(data) click to toggle source

@private

# File lib/moped/bson/object_id.rb, line 127
def marshal_load(data)
  self.data = data
end
to_json(*args) click to toggle source
# File lib/moped/bson/object_id.rb, line 65
def to_json(*args)
  "{\"$oid\": \"#{to_s}\"}"
end
to_s() click to toggle source
# File lib/moped/bson/object_id.rb, line 56
def to_s
  data.unpack("H*")[0]
end
Also aliased as: to_str
to_str() click to toggle source
Alias for: to_s

[Validate]

Generated with the Darkfish Rdoc Generator 2.