Class: MongoRequestLogger::Adapters::Moped
- Inherits:
-
Base
- Object
- Base
- MongoRequestLogger::Adapters::Moped
show all
- Defined in:
- lib/mongo_request_logger/adapters/moped.rb
Class Attribute Summary collapse
Attributes inherited from Base
#authenticated, #collection, #configuration, #connection, #connection_type
Instance Method Summary
collapse
Methods inherited from Base
#authenticated?, #capsize, #check_for_collection, #collection_name, #collection_stats_hash, #reconnect, #reset_collection
Constructor Details
#initialize(session) ⇒ Moped
Returns a new instance of Moped.
13
14
15
16
17
18
19
20
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 13
def initialize(session)
@connection = session
MongoRequestLogger::Adapters::Moped.connection = @connection
@connection_type = @connection.class
check_for_collection
end
|
Class Attribute Details
.connection ⇒ Object
Returns the value of attribute connection.
9
10
11
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 9
def connection
@connection
end
|
Instance Method Details
#clear! ⇒ Object
57
58
59
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 57
def clear!
@collection.drop
end
|
#collection_stats ⇒ Object
41
42
43
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 41
def collection_stats
collection_stats_hash(@connection.command(collStats: collection_name))
end
|
#create_collection ⇒ Object
26
27
28
29
30
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 26
def create_collection
@connection.cluster.with_primary do |node|
node.command(@connection.send(:current_database).name, {create: collection_name, capped: true, size: capsize})
end
end
|
#create_index(field) ⇒ Object
32
33
34
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 32
def create_index field
@collection.indexes.create({field => 1})
end
|
#find_by_id(id) ⇒ Object
53
54
55
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 53
def find_by_id(id)
@collection.find("_id" => ::Moped::BSON::ObjectId.from_string(id)).first
end
|
#insert_log_record(record) ⇒ Object
36
37
38
39
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 36
def insert_log_record(record)
record[:_id] = ::Moped::BSON::ObjectId.new
@connection.with(safe: false)[collection_name].insert(record)
end
|
#options ⇒ Object
22
23
24
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 22
def options
@connection.options
end
|
#query(criteria, options = {}) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/mongo_request_logger/adapters/moped.rb', line 45
def query(criteria, options={})
q = @collection.find(criteria).sort({'timestamp' => -1})
if options[:limit]
q = q.limit(options[:limit])
end
q
end
|