Class: Vayacondios::Server::DocumentHandler

Inherits:
Object
  • Object
show all
Includes:
Goliath::Chimp::Handler
Defined in:
lib/vayacondios/server/handlers/document_handler.rb

Overview

Generic handler for all documents.

Handlers link HTTP applications to document classes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log, db) ⇒ DocumentHandler

Create a new DocumentHandler.

Parameters:

  • log (Logger)


17
18
19
20
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 17

def initialize(log, db)
  @log = log
  @database = db
end

Instance Attribute Details

#databaseDriver

the database driver

Returns:

  • (Driver)

    the current value of database



9
10
11
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 9

def database
  @database
end

#logLogger

the log to use

Returns:

  • (Logger)

    the current value of log



9
10
11
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 9

def log
  @log
end

Instance Method Details

#action_successfulObject



77
78
79
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 77

def action_successful
  { ok: true }
end

#base_create(params, document) ⇒ Hash

Create a document.

Parameters:

  • params (Hash)

    routing information like ‘organization`, `topic,`, or `id`

  • document (Hash)

    the body of the document

Returns:

  • (Hash)

    the created document



37
38
39
40
41
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 37

def base_create(params, document)
  log.debug("Processing by #{self.class}#create")
  log.debug("  Parameters: #{params.inspect}")
  log.debug("  Document:   #{document.inspect}")
end

#base_delete(params, document) ⇒ Hash

Delete a document.

Parameters:

  • params (Hash)

    routing information like ‘organization`, `topic,`, or `id`

Returns:

  • (Hash)

    details about which documents were deleted



67
68
69
70
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 67

def base_delete(params, document)
  log.debug("Processing by #{self.class}#delete")
  log.debug("  Parameters: #{params.inspect}")
end

#base_retrieve(params, document) ⇒ Object

Find and show a particular document.

Parameters:

  • params (Hash)

    routing information like ‘organization`, `topic,`, or `id`

Returns:

  • (Object)

    the document (or part of a document) that was found



47
48
49
50
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 47

def base_retrieve(params, document)
  log.debug("Processing by #{self.class}#retrieve")
  log.debug("  Parameters: #{params.inspect}")
end

#base_search(params, query) ⇒ Array<Hash>

Search for matching documents.

Parameters:

  • query (Hash)

    the search query

Returns:

  • (Array<Hash>)

    the matching documents



26
27
28
29
30
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 26

def base_search(params, query)
  log.debug("Processing by #{self.class}#search")
  log.debug("  Parameters: #{params.inspect}")
  log.debug("  Query:      #{query.inspect}")
end

#base_update(params, document) ⇒ Object

Update a document.

Parameters:

  • params (Hash)

    routing information like ‘organization`, `topic,`, or `id`

  • document (Hash)

    the body of the document

Returns:

  • (Object)

    the document (or part a document) that was updated



57
58
59
60
61
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 57

def base_update(params, document)
  log.debug("Processing by #{self.class}#update")
  log.debug("  Parameters: #{params.inspect}")
  log.debug("  Document:   #{document.inspect}")
end

#call(name, params, document) ⇒ Object



72
73
74
75
# File 'lib/vayacondios/server/handlers/document_handler.rb', line 72

def call(name, params, document)
  send("base_#{name}", params, document)
  send(name, params, document)
end