class Fauna::Context

The client context wrapper.

Used for accessing the client without directly passing around the client instance. Context is scoped to the current thread.

Public Class Methods

block(client) { || ... } click to toggle source

Returns a context block with the given client.

client

Client to use for the context block.

   # File lib/fauna/context.rb
16 def self.block(client)
17   push(client)
18   yield
19 ensure
20   pop
21 end
client() click to toggle source

Returns the current context's client, or if there is none, raises NoContextError.

    # File lib/fauna/context.rb
134 def self.client
135   stack.last || fail(NoContextError, 'You must be within a Fauna::Context.block to perform operations.')
136 end
paginate(set, params = {}, &fauna_map) click to toggle source

Creates a Fauna::Page for paging/iterating over a set with the current client context.

set

A set query to paginate over.

params

A list of parameters to pass to paginate.

fauna_map

Optional block to wrap the generated paginate query with. The block will be run in a query context. The paginate query will be passed into the block as an argument.

    # File lib/fauna/context.rb
128 def self.paginate(set, params = {}, &fauna_map)
129   client.paginate(set, params, &fauna_map)
130 end
pop() click to toggle source

Removes the last client context from the stack and returns it.

   # File lib/fauna/context.rb
33 def self.pop
34   stack.pop
35 end
push(client) click to toggle source

Adds a client to the current context.

client

Client to add to the current context.

   # File lib/fauna/context.rb
27 def self.push(client)
28   stack.push(client)
29 end
reset() click to toggle source

Resets the current client context, removing all the clients from the stack.

   # File lib/fauna/context.rb
39 def self.reset
40   stack.clear
41 end

Private Class Methods

stack() click to toggle source
    # File lib/fauna/context.rb
141 def stack
142   Thread.current[:fauna_context_stack] ||= []
143 end

Client Methods

↑ top

Public Class Methods

delete(path) click to toggle source

Performs a DELETE request for a REST endpoint within the current client context.

path

Path to DELETE.

data

Data to post as the body.

Reference: FaunaDB REST API

    # File lib/fauna/context.rb
104 def self.delete(path)
105   client.delete(path)
106 end
get(path, query = {}) click to toggle source

Performs a GET request for a REST endpoint within the current client context.

path

Path to GET.

query

Query parameters to append to the path.

Reference: FaunaDB REST API

   # File lib/fauna/context.rb
52 def self.get(path, query = {})
53   client.get(path, query)
54 end
patch(path, data = {}) click to toggle source

Performs a PATCH request for a REST endpoint within the current client context.

path

Path to PATCH.

data

Data to post as the body.

Reference: FaunaDB REST API

   # File lib/fauna/context.rb
91 def self.patch(path, data = {})
92   client.patch(path, data)
93 end
post(path, data = {}) click to toggle source

Performs a POST request for a REST endpoint within the current client context.

path

Path to POST.

data

Data to post as the body.

Reference: FaunaDB REST API

   # File lib/fauna/context.rb
65 def self.post(path, data = {})
66   client.post(path, data)
67 end
put(path, data = {}) click to toggle source

Performs a PUT request for a REST endpoint within the current client context.

path

Path to PUT.

data

Data to post as the body.

Reference: FaunaDB REST API

   # File lib/fauna/context.rb
78 def self.put(path, data = {})
79   client.put(path, data)
80 end
query(expression = nil, &expr_block) click to toggle source

Issues a query to FaunaDB with the current client context.

Queries are built via the Query helpers. See FaunaDB Query API for information on constructing queries.

expression

A query expression

    # File lib/fauna/context.rb
117 def self.query(expression = nil, &expr_block)
118   client.query(expression, &expr_block)
119 end