Class: Moped::Protocol::Delete

Inherits:
Object
  • Object
show all
Includes:
Message
Defined in:
lib/moped/protocol/delete.rb

Overview

The Protocol class for deleting documents from a collection.

Examples:

Delete all people named John

delete = Delete.new "moped", "people", { name: "John" }

Delete the first person named John

delete = Delete.new "moped", "people", { name: "John" },
  flags: [:remove_first]

Setting the request id

delete = Delete.new "moped", "people", { name: "John" },
  request_id: 123

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Message

included, #inspect, #receive_replies, #serialize

Constructor Details

#initialize(database, collection, selector, options = {}) ⇒ Delete

Create a new delete command. The database and collection arguments are joined together to set the full_collection_name.

Examples:

Delete.new "moped", "users", { condition: true },
  flags: [:remove_first],
  request_id: 123

Parameters:

  • database (String, Symbol)

    the database to delete from

  • collection (String, Symbol)

    the collection to delete from

  • selector (Hash)

    the selector for which documents to delete

  • options (Hash) (defaults to: {})

    additional options

Options Hash (options):

  • :request_id (Number)

    the command’s request id

  • :flags (Array)

    the flags for insertion. Supported flags: :remove_first



71
72
73
74
75
76
77
78
79
# File 'lib/moped/protocol/delete.rb', line 71

def initialize(database, collection, selector, options = {})
  @database   = database
  @collection = collection

  @full_collection_name = "#{database}.#{collection}"
  @selector             = selector
  @request_id           = options[:request_id]
  @flags                = options[:flags]
end

Instance Attribute Details

#collectionString, Symbol (readonly)

Returns the collection to delete from.

Returns:



54
55
56
# File 'lib/moped/protocol/delete.rb', line 54

def collection
  @collection
end

#databaseString, Symbol (readonly)

Returns the database to delete from.

Returns:



51
52
53
# File 'lib/moped/protocol/delete.rb', line 51

def database
  @database
end

#flagsArray

Returns the flags for the message.

Parameters:

  • the (Array)

    flags for the message

Returns:

  • (Array)

    the flags for the message



42
# File 'lib/moped/protocol/delete.rb', line 42

flags    :flags, remove_first: 2 ** 0

#full_collection_nameString

Returns the full collection name.

Returns:

  • (String)

    the full collection name



37
# File 'lib/moped/protocol/delete.rb', line 37

cstring  :full_collection_name

#lengthNumber

Returns the length of the message.

Returns:

  • (Number)

    the length of the message



21
# File 'lib/moped/protocol/delete.rb', line 21

int32 :length

#op_codeNumber

Returns OP_DELETE operation code (2006).

Returns:

  • (Number)

    OP_DELETE operation code (2006)



31
# File 'lib/moped/protocol/delete.rb', line 31

int32 :op_code

#request_idNumber

Returns the request id of the message.

Returns:

  • (Number)

    the request id of the message



25
# File 'lib/moped/protocol/delete.rb', line 25

int32 :request_id

#selectorHash

Returns the query to use when deleting documents.

Returns:

  • (Hash)

    the query to use when deleting documents



46
# File 'lib/moped/protocol/delete.rb', line 46

document :selector

Instance Method Details

#log_inspectObject



87
88
89
90
91
# File 'lib/moped/protocol/delete.rb', line 87

def log_inspect
  type = "DELETE"

  "%-12s database=%s collection=%s selector=%s flags=%s" % [type, database, collection, selector.inspect, flags.inspect]
end