Class: Mongo::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/collection.rb

Overview

Represents a collection in the database and operations that can directly be applied to one.

Since:

  • 3.0.0

Defined Under Namespace

Classes: InvalidName

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database, name) ⇒ Collection

@todo: durran: implement.

Raises:

Since:

  • 3.0.0



45
46
47
48
49
# File 'lib/mongo/collection.rb', line 45

def initialize(database, name)
  raise InvalidName.new unless name
  @database = database
  @name = name.to_s
end

Instance Attribute Details

#databaseMongo::Database (readonly)

Returns The database the collection resides in.

Returns:

Since:

  • 3.0.0



24
25
26
# File 'lib/mongo/collection.rb', line 24

def database
  @database
end

#nameString (readonly)

Returns The name of the collection.

Returns:

  • (String)

    The name of the collection.

Since:

  • 3.0.0



26
27
28
# File 'lib/mongo/collection.rb', line 26

def name
  @name
end

Instance Method Details

#==(other) ⇒ true, false

Check if a collection is equal to another object. Will check the name and the database for equality.

Examples:

Check collection equality.

collection == other

Parameters:

  • other (Object)

    The object to check.

Returns:

  • (true, false)

    If the objects are equal.

Since:

  • 3.0.0



39
40
41
42
# File 'lib/mongo/collection.rb', line 39

def ==(other)
  return false unless other.is_a?(Collection)
  name == other.name && database == other.database
end