Class: XGen::Mongo::Driver::Admin
- Inherits:
-
Object
- Object
- XGen::Mongo::Driver::Admin
- Defined in:
- lib/mongo/admin.rb
Overview
Provide administrative database methods: those having to do with profiling and validation.
Instance Method Summary collapse
-
#initialize(db) ⇒ Admin
constructor
A new instance of Admin.
-
#profiling_info ⇒ Object
Return an array contining current profiling information from the database.
-
#profiling_level ⇒ Object
Return the current database profiling level.
-
#profiling_level=(level) ⇒ Object
Set database profiling level to :off, :slow_only, or :all.
-
#validate_collection(name) ⇒ Object
Validate a named collection by raising an exception if there is a problem or returning an interesting hash (see especially the ‘result’ string value) if all is well.
Constructor Details
#initialize(db) ⇒ Admin
Returns a new instance of Admin.
27 28 29 |
# File 'lib/mongo/admin.rb', line 27 def initialize(db) @db = db end |
Instance Method Details
#profiling_info ⇒ Object
Return an array contining current profiling information from the database.
68 69 70 |
# File 'lib/mongo/admin.rb', line 68 def profiling_info @db.query(Collection.new(@db, DB::SYSTEM_PROFILE_COLLECTION), Query.new({})).to_a end |
#profiling_level ⇒ Object
Return the current database profiling level.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mongo/admin.rb', line 32 def profiling_level oh = OrderedHash.new oh[:profile] = -1 doc = @db.db_command(oh) raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc) && doc['was'].kind_of?(Numeric) case doc['was'].to_i when 0 :off when 1 :slow_only when 2 :all else raise "Error: illegal profiling level value #{doc['was']}" end end |
#profiling_level=(level) ⇒ Object
Set database profiling level to :off, :slow_only, or :all.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mongo/admin.rb', line 50 def profiling_level=(level) oh = OrderedHash.new oh[:profile] = case level when :off 0 when :slow_only 1 when :all 2 else raise "Error: illegal profiling level value #{level}" end doc = @db.db_command(oh) raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc) end |
#validate_collection(name) ⇒ Object
Validate a named collection by raising an exception if there is a problem or returning an interesting hash (see especially the ‘result’ string value) if all is well.
75 76 77 78 79 80 81 82 |
# File 'lib/mongo/admin.rb', line 75 def validate_collection(name) doc = @db.db_command(:validate => name) raise "Error with validate command: #{doc.inspect}" unless @db.ok?(doc) result = doc['result'] raise "Error with validation data: #{doc.inspect}" unless result.kind_of?(String) raise "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i doc end |