Class: Rack::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/rackjson/rack/builder.rb

Instance Method Summary collapse

Instance Method Details

#expose_resource(options) ⇒ Object

Setup resource collections without authentication.

Example

expose_resource :collections => [:notes, :projects], :db => @mongo_db


8
9
10
11
12
# File 'lib/rackjson/rack/builder.rb', line 8

def expose_resource options
  @ins << lambda do |app|
    Rack::JSON::Resource.new app, options
  end
end

#private_resource(options) ⇒ Object

Setup resource collections with no public access. Read and write access only given to the owner of the document, determened from the session vars passed as filters.

Example

private_resource :collections => [:notes, :projects], :db => @mongo_db, :filters => [:user_id]


36
37
38
39
40
41
42
# File 'lib/rackjson/rack/builder.rb', line 36

def private_resource options
  @ins << lambda do |app|
    Rack::JSON::Filter.new(
      Rack::JSON::Resource.new(app, options),
      options.merge(:methods => [:get, :post, :put, :delete]))
  end
end

#public_resource(options) ⇒ Object

Setup resource collections with public read access but write access only given to the owner of the document, determened from the session var passed as filter.

Example

public_resource :collections => [:notes, :projects], :db => @mongo_db, :filters => [:user_id]


21
22
23
24
25
26
27
# File 'lib/rackjson/rack/builder.rb', line 21

def public_resource options
  @ins << lambda do |app|
    Rack::JSON::Filter.new(
      Rack::JSON::Resource.new(app, options),
      options.merge(:methods => [:post, :put, :delete]))
  end
end