Module: Rack::GridFS::Endpoint::Base

Included in:
Rack::GridFS::Endpoint
Defined in:
lib/rack/gridfs/endpoint/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



5
6
7
# File 'lib/rack/gridfs/endpoint/base.rb', line 5

def db
  @db
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/rack/gridfs/endpoint/base.rb', line 15

def call(env)
  with_rescues do
    request = Rack::Request.new(env)
    key     = key_for_path(request.path_info)
    file    = find_file(key)

    response_for(file, request)
  end
end

#initialize(options = {}) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/rack/gridfs/endpoint/base.rb', line 7

def initialize(options = {})
  @options = default_options.merge(options)

  @db     = @options[:db]
  @lookup = @options[:lookup]
  @mapper = @options[:mapper]
end

#key_for_path(path) ⇒ Object



25
26
27
# File 'lib/rack/gridfs/endpoint/base.rb', line 25

def key_for_path(path)
  @mapper.respond_to?(:call) ? @mapper.call(path) : path
end