Class: MongodbLogger::Adapers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mongodb_logger/adapters/base.rb

Direct Known Subclasses

Mongo, Moped

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authenticatedObject (readonly)

Returns the value of attribute authenticated.



5
6
7
# File 'lib/mongodb_logger/adapters/base.rb', line 5

def authenticated
  @authenticated
end

#collectionObject (readonly)

Returns the value of attribute collection.



5
6
7
# File 'lib/mongodb_logger/adapters/base.rb', line 5

def collection
  @collection
end

#configurationObject (readonly)

Returns the value of attribute configuration.



5
6
7
# File 'lib/mongodb_logger/adapters/base.rb', line 5

def configuration
  @configuration
end

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/mongodb_logger/adapters/base.rb', line 5

def connection
  @connection
end

#connection_typeObject (readonly)

Returns the value of attribute connection_type.



5
6
7
# File 'lib/mongodb_logger/adapters/base.rb', line 5

def connection_type
  @connection_type
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/mongodb_logger/adapters/base.rb', line 11

def authenticated?
  @authenticated
end

#check_for_collectionObject



15
16
17
18
19
# File 'lib/mongodb_logger/adapters/base.rb', line 15

def check_for_collection
  # setup the capped collection if it doesn't already exist
  create_collection unless @connection.collection_names.include?(@configuration[:collection])
  @collection = @connection[@configuration[:collection]]
end

#collection_nameObject



7
8
9
# File 'lib/mongodb_logger/adapters/base.rb', line 7

def collection_name
  @configuration[:collection]
end

#collection_stats_hash(stats) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/mongodb_logger/adapters/base.rb', line 32

def collection_stats_hash(stats)
  {
    is_capped: (stats["capped"] && ([1, true].include?(stats["capped"]))),
    count: stats["count"].to_i,
    size: stats["size"].to_f,
    storageSize: stats["storageSize"].to_f,
    db_name: @configuration["database"],
    collection: collection_name
  }
end

#create_collectionObject



43
44
45
# File 'lib/mongodb_logger/adapters/base.rb', line 43

def create_collection
  raise "Not implemented"
end

#rename_collection_command(admin_session, to, drop_target = false) ⇒ Object



21
22
23
# File 'lib/mongodb_logger/adapters/base.rb', line 21

def rename_collection_command(admin_session, to, drop_target = false)
  admin_session.command(renameCollection: "#{@configuration[:database]}.#{collection_name}", to: "#{@configuration[:database]}.#{to}", dropTarget: drop_target)
end

#reset_collectionObject



25
26
27
28
29
30
# File 'lib/mongodb_logger/adapters/base.rb', line 25

def reset_collection
  if @connection && @collection
    @collection.drop
    create_collection
  end
end