Module: Toy::Mongo::Querying::ClassMethods

Defined in:
lib/toy/mongo/querying.rb

Instance Method Summary collapse

Instance Method Details

#get(id) ⇒ Object



24
25
26
# File 'lib/toy/mongo/querying.rb', line 24

def get(id)
  super Plucky.to_object_id(id)
end

#object_id_attributesObject



15
16
17
18
19
20
21
22
# File 'lib/toy/mongo/querying.rb', line 15

def object_id_attributes
  attributes.values.select do |attribute|
    attribute.type == BSON::ObjectId
  end.map do |attribute|
    sym = attribute.name.to_sym
    sym == :id ? :_id : sym
  end
end

#queryObject



28
29
30
# File 'lib/toy/mongo/querying.rb', line 28

def query
  Plucky::Query.new(adapter.client, :transformer => transformer).object_ids(object_id_attributes)
end

#transformerObject



9
10
11
12
13
# File 'lib/toy/mongo/querying.rb', line 9

def transformer
  @transformer ||= lambda do |doc|
    load(doc.delete('_id'), doc)
  end
end