Class: Griddleware::GridFile

Inherits:
Object
  • Object
show all
Defined in:
lib/griddleware/grid_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ GridFile

Returns a new instance of GridFile.



4
5
6
# File 'lib/griddleware/grid_file.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/griddleware/grid_file.rb', line 8

def call(env)
  rack = Rack::Request.new(env)
  if rack.path =~ /^\/grid\/([\w]+)\/([\w]+)\/(.+)$/
    owner_type, owner_id = [$1.classify, $2]
    style_path = $3.split('/')
    file_name = style_path.pop
    name = style_path.join("/")
    record = {
      :name => name,
      :owner_type => owner_type,
      :owner_id => owner_id
    }
    attachment = Griddle::Attachment.attachment_for(record)
    [200, {"Content-Type" => attachment.content_type}, attachment.file.read]
  else
    @app.call(env)
  end
end

#each(&block) ⇒ Object



27
28
29
# File 'lib/griddleware/grid_file.rb', line 27

def each(&block)
  @response.each(&block)
end