Class: Moped::Session::Context Private
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
- #session ⇒ Object readonly private
Instance Method Summary collapse
- #cluster ⇒ Object private
- #command(database, command) ⇒ Object private
- #consistency ⇒ Object private
- #get_more(*args) ⇒ Object private
-
#initialize(session) ⇒ Context
constructor
private
A new instance of Context.
- #insert(database, collection, documents, options = {}) ⇒ Object private
- #kill_cursors(*args) ⇒ Object private
- #login(database, username, password) ⇒ Object private
- #logout(database) ⇒ Object private
- #query(database, collection, selector, options = {}) ⇒ Object private
- #remove(database, collection, selector, options = {}) ⇒ Object private
- #safe? ⇒ Boolean private
- #safety ⇒ Object private
- #update(database, collection, selector, change, options = {}) ⇒ Object private
- #with_node ⇒ Object private
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
#session ⇒ Object (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
#cluster ⇒ 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.
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) = consistency == :eventual ? { :flags => [:slave_ok] } : {} with_node do |node| node.command(database, command, ) end end |
#consistency ⇒ 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.
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.
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, = {}) with_node do |node| if safe? node.pipeline do node.insert(database, collection, documents, ) node.command(database, { getlasterror: 1 }.merge(safety)) end else node.insert(database, collection, documents, ) 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.
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 login(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, = {}) if consistency == :eventual [:flags] ||= [] [:flags] |= [:slave_ok] end with_node do |node| node.query(database, collection, selector, ) 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, = {}) with_node do |node| if safe? node.pipeline do node.remove(database, collection, selector, ) node.command(database, { getlasterror: 1 }.merge(safety)) end else node.remove(database, collection, selector, ) 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.
17 18 19 |
# File 'lib/moped/session/context.rb', line 17 def safe? session.safe? end |
#safety ⇒ 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.
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, = {}) with_node do |node| if safe? node.pipeline do node.update(database, collection, selector, change, ) node.command(database, { getlasterror: 1 }.merge(safety)) end else node.update(database, collection, selector, change, ) end end end |
#with_node ⇒ 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.
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 |