Module: EM::Mongo::Support
- Extended by:
- Support
- Includes:
- Conversions
- Included in:
- Support
- Defined in:
- lib/em-mongo/support.rb
Constant Summary
Constant Summary
Constants included from Conversions
Conversions::ASCENDING_CONVERSION, Conversions::DESCENDING_CONVERSION
Instance Method Summary (collapse)
-
- (String) auth_key(username, password, nonce)
Generate an MD5 for authentication.
- - (Object) format_order_clause(order)
-
- (String) hash_password(username, plaintext)
Return a hashed password for auth.
-
- (Boolean) ok?(doc)
Determine if a database command has succeeded by checking the document response.
- - (Object) validate_db_name(db_name)
Methods included from Conversions
#array_as_sort_parameters, #sort_value, #string_as_sort_parameters
Instance Method Details
- (String) auth_key(username, password, nonce)
Generate an MD5 for authentication.
33 34 35 |
# File 'lib/em-mongo/support.rb', line 33 def auth_key(username, password, nonce) Digest::MD5.hexdigest("#{nonce}#{username}#{hash_password(username, password)}") end |
- (Object) format_order_clause(order)
62 63 64 65 66 67 68 69 70 |
# File 'lib/em-mongo/support.rb', line 62 def format_order_clause(order) case order when String, Symbol then string_as_sort_parameters(order) when Array then array_as_sort_parameters(order) else raise InvalidSortValueError, "Illegal sort clause, '#{order.class.name}'; must be of the form " + "[['field1', '(ascending|descending)'], ['field2', '(ascending|descending)']]" end end |
- (String) hash_password(username, plaintext)
Return a hashed password for auth.
43 44 45 |
# File 'lib/em-mongo/support.rb', line 43 def hash_password(username, plaintext) Digest::MD5.hexdigest("#{username}:mongo:#{plaintext}") end |
- (Boolean) ok?(doc)
Determine if a database command has succeeded by checking the document response.
78 79 80 |
# File 'lib/em-mongo/support.rb', line 78 def ok?(doc) doc['ok'] == 1.0 || doc['ok'] == true end |
- (Object) validate_db_name(db_name)
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/em-mongo/support.rb', line 48 def validate_db_name(db_name) unless [String, Symbol].include?(db_name.class) raise TypeError, "db_name must be a string or symbol" end [" ", ".", "$", "/", "\\"].each do |invalid_char| if db_name.include? invalid_char raise EM::Mongo::InvalidNSName, "database names cannot contain the character '#{invalid_char}'" end end raise EM::Mongo::InvalidNSName, "database name cannot be the empty string" if db_name.empty? db_name end |