Module: DataMapper::Aspects::BSONID

Defined in:
lib/datamapper/aspects/bson_id.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/datamapper/aspects/bson_id.rb', line 6

def self.included(base)
  base.property :id, String, length: 24, key: true, default: Moped::BSON::ObjectId.new.to_s
  base.validates_with_method :id, method: :id_is_valid?

  def id_generation_time
    Moped::BSON::ObjectId.from_string(@id).generation_time
  end

  def id_is_valid?
    Moped::BSON::Objectid.legal?(@id)
  end
end

Instance Method Details

#id_generation_timeObject



10
11
12
# File 'lib/datamapper/aspects/bson_id.rb', line 10

def id_generation_time
  Moped::BSON::ObjectId.from_string(@id).generation_time
end

#id_is_valid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/datamapper/aspects/bson_id.rb', line 14

def id_is_valid?
  Moped::BSON::Objectid.legal?(@id)
end