Class: Moped::Session::Context Private

Inherits:
Object
  • Object
show all
Defined in:
lib/moped/session/context.rb

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Context

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.

Returns a new instance of Context.



9
10
11
# File 'lib/moped/session/context.rb', line 9

def initialize(session)
  @session = session
end

Instance Attribute Details

#sessionObject (readonly)

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.



7
8
9
# File 'lib/moped/session/context.rb', line 7

def session
  @session
end

Instance Method Details

#clusterObject

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.



25
26
27
# File 'lib/moped/session/context.rb', line 25

def cluster
  session.cluster
end

#command(database, command) ⇒ Object

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.



48
49
50
51
52
53
# File 'lib/moped/session/context.rb', line 48

def command(database, command)
  options = consistency == :eventual ? { :flags => [:slave_ok] } : {}
  with_node do |node|
    node.command(database, command, options)
  end
end

#consistencyObject

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.



21
22
23
# File 'lib/moped/session/context.rb', line 21

def consistency
  session.consistency
end

#get_more(*args) ⇒ Object

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.

Raises:

  • (NotImplementedError)


94
95
96
# File 'lib/moped/session/context.rb', line 94

def get_more(*args)
  raise NotImplementedError, "#get_more cannot be called on Context; it must be called directly on a node"
end

#insert(database, collection, documents, options = {}) ⇒ Object

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.



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/moped/session/context.rb', line 55

def insert(database, collection, documents, options = {})
  with_node do |node|
    if safe?
      node.pipeline do
        node.insert(database, collection, documents, options)
        node.command(database, { getlasterror: 1 }.merge(safety))
      end
    else
      node.insert(database, collection, documents, options)
    end
  end
end

#kill_cursors(*args) ⇒ Object

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.

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/moped/session/context.rb', line 98

def kill_cursors(*args)
  raise NotImplementedError, "#kill_cursors cannot be called on Context; it must be called directly on a node"
end

#login(database, username, password) ⇒ Object

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.



29
30
31
# File 'lib/moped/session/context.rb', line 29

def (database, username, password)
  cluster.auth[database.to_s] = [username, password]
end

#logout(database) ⇒ Object

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.



33
34
35
# File 'lib/moped/session/context.rb', line 33

def logout(database)
  cluster.auth.delete database.to_s
end

#query(database, collection, selector, options = {}) ⇒ Object

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.



37
38
39
40
41
42
43
44
45
46
# File 'lib/moped/session/context.rb', line 37

def query(database, collection, selector, options = {})
  if consistency == :eventual
    options[:flags] ||= []
    options[:flags] |= [:slave_ok]
  end

  with_node do |node|
    node.query(database, collection, selector, options)
  end
end

#remove(database, collection, selector, options = {}) ⇒ Object

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.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/moped/session/context.rb', line 81

def remove(database, collection, selector, options = {})
  with_node do |node|
    if safe?
      node.pipeline do
        node.remove(database, collection, selector, options)
        node.command(database, { getlasterror: 1 }.merge(safety))
      end
    else
      node.remove(database, collection, selector, options)
    end
  end
end

#safe?Boolean

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.

Returns:

  • (Boolean)


17
18
19
# File 'lib/moped/session/context.rb', line 17

def safe?
  session.safe?
end

#safetyObject

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.



13
14
15
# File 'lib/moped/session/context.rb', line 13

def safety
  session.safety
end

#update(database, collection, selector, change, options = {}) ⇒ Object

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.



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/moped/session/context.rb', line 68

def update(database, collection, selector, change, options = {})
  with_node do |node|
    if safe?
      node.pipeline do
        node.update(database, collection, selector, change, options)
        node.command(database, { getlasterror: 1 }.merge(safety))
      end
    else
      node.update(database, collection, selector, change, options)
    end
  end
end

#with_nodeObject

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.



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/moped/session/context.rb', line 102

def with_node
  if consistency == :eventual
    cluster.with_secondary do |node|
      yield node
    end
  else
    cluster.with_primary do |node|
      yield node
    end
  end
end