Class: Daodalus::DSL::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/daodalus/dsl/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wheres = {}, selects = {}, updates = {}) ⇒ Query

Returns a new instance of Query.



5
6
7
8
9
# File 'lib/daodalus/dsl/query.rb', line 5

def initialize(wheres={}, selects={}, updates={})
  @wheres  = wheres
  @selects = selects
  @updates = updates
end

Instance Attribute Details

#updatesObject (readonly)

Returns the value of attribute updates.



10
11
12
# File 'lib/daodalus/dsl/query.rb', line 10

def updates
  @updates
end

#wheresObject (readonly)

Returns the value of attribute wheres.



10
11
12
# File 'lib/daodalus/dsl/query.rb', line 10

def wheres
  @wheres
end

Instance Method Details

#has_selects?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/daodalus/dsl/query.rb', line 28

def has_selects?
  !selects.empty?
end

#select(clause) ⇒ Object



20
21
22
# File 'lib/daodalus/dsl/query.rb', line 20

def select clause
  Query.new(wheres, selects.merge(clause), updates)
end

#selectsObject



24
25
26
# File 'lib/daodalus/dsl/query.rb', line 24

def selects
  @selects.empty? ? @selects : {'_id' => 0}.merge(@selects)
end

#update(clause) ⇒ Object



16
17
18
# File 'lib/daodalus/dsl/query.rb', line 16

def update clause
  Query.new(wheres, selects, updates.merge(clause))
end

#where(clause) ⇒ Object



12
13
14
# File 'lib/daodalus/dsl/query.rb', line 12

def where clause
  Query.new(add_where(clause), selects, updates)
end