Class: ROM::Mongo::Dataset

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/mongo/dataset.rb

Defined Under Namespace

Classes: Criteria

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, criteria = Criteria.new) ⇒ Dataset

Returns a new instance of Dataset.



10
11
12
13
# File 'lib/rom/mongo/dataset.rb', line 10

def initialize(collection, criteria = Criteria.new)
  @collection = collection
  @criteria = criteria
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



15
16
17
# File 'lib/rom/mongo/dataset.rb', line 15

def collection
  @collection
end

#criteriaObject (readonly)

Returns the value of attribute criteria.



17
18
19
# File 'lib/rom/mongo/dataset.rb', line 17

def criteria
  @criteria
end

Instance Method Details

#eachObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
# File 'lib/rom/mongo/dataset.rb', line 28

def each
  view.each { |doc| yield(doc) }
end

#find(criteria = {}) ⇒ Object



19
20
21
# File 'lib/rom/mongo/dataset.rb', line 19

def find(criteria = {})
  Dataset.new(collection, Criteria.new.where(criteria))
end

#insert(data) ⇒ Object



32
33
34
# File 'lib/rom/mongo/dataset.rb', line 32

def insert(data)
  collection.insert_one(data)
end

#limit(limit) ⇒ Object



56
57
58
# File 'lib/rom/mongo/dataset.rb', line 56

def limit(limit)
  dataset(criteria.limit(limit))
end

#only(fields) ⇒ Object



48
49
50
# File 'lib/rom/mongo/dataset.rb', line 48

def only(fields)
  dataset(criteria.only(fields))
end

#order(value) ⇒ Object



64
65
66
# File 'lib/rom/mongo/dataset.rb', line 64

def order(value)
  dataset(criteria.order(value))
end

#remove_allObject



40
41
42
# File 'lib/rom/mongo/dataset.rb', line 40

def remove_all
  view.delete_many
end

#skip(value) ⇒ Object



60
61
62
# File 'lib/rom/mongo/dataset.rb', line 60

def skip(value)
  dataset(criteria.skip(value))
end

#to_aObject



23
24
25
# File 'lib/rom/mongo/dataset.rb', line 23

def to_a
  view.to_a
end

#update_all(attributes) ⇒ Object



36
37
38
# File 'lib/rom/mongo/dataset.rb', line 36

def update_all(attributes)
  view.update_many(attributes)
end

#where(doc) ⇒ Object



44
45
46
# File 'lib/rom/mongo/dataset.rb', line 44

def where(doc)
  dataset(criteria.where(doc))
end

#without(fields) ⇒ Object



52
53
54
# File 'lib/rom/mongo/dataset.rb', line 52

def without(fields)
  dataset(criteria.without(fields))
end