Class: Vayacondios::Server::StashHandler

Inherits:
DocumentHandler show all
Defined in:
lib/vayacondios/server/handlers/stash_handler.rb

Instance Attribute Summary

Attributes inherited from DocumentHandler

#database, #log

Instance Method Summary collapse

Methods inherited from DocumentHandler

#action_successful, #base_create, #base_delete, #base_retrieve, #base_search, #base_update, #call, #initialize

Constructor Details

This class inherits a constructor from Vayacondios::Server::DocumentHandler

Instance Method Details

#create(params, document) ⇒ Object

Create a stash.

Parameters:

  • params (Hash)

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

  • document (Hash)

    the body of the stash



8
9
10
11
12
13
14
# File 'lib/vayacondios/server/handlers/stash_handler.rb', line 8

def create(params, document)      
  stash = Stash.create(params, document) do |request|
    database.call(:insert, request)
  end
  stash.delete(:topic)
  stash
end

#delete(params, document) ⇒ Object

Delete a single stash.

Parameters:

  • params (Hash)

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

  • document (Hash)

    presentation or filter information



61
62
63
64
65
66
67
# File 'lib/vayacondios/server/handlers/stash_handler.rb', line 61

def delete(params, document)
  raise Goliath::Validation::NotImplementedError.new 'Deleting an Id from a Stash is not supported' if params[:id]
  Stash.destroy(params, {}) do |request, options|
    database.call(:remove, request, options)
  end
  action_successful
end

#retrieve(params, document) ⇒ Object

Find and show a particular stash.

Parameters:

  • params (Hash)

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

Raises:

  • (Goliath::Validation::Error)

    if no stash is found. Returns a 404.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vayacondios/server/handlers/stash_handler.rb', line 20

def retrieve(params, document)
  stash = Stash.find(params) do |request|
    database.call(:retrieve, request)
  end or raise Goliath::Validation::NotFoundError.new("Stash with topic <#{params[:topic]}> not found")
  stash.delete(:topic)
  if slice = params[:id]
    stash[slice.to_sym] or raise Goliath::Validation::NotFoundError.new("Stash with topic <#{params[:topic]}> found, but does not contain Id <#{slice}>")
  else
    stash
  end
end