Class: Griddleware::GridFile
- Inherits:
-
Object
- Object
- Griddleware::GridFile
- Defined in:
- lib/griddleware/grid_file.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(app) ⇒ GridFile
constructor
A new instance of GridFile.
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 } = Griddle::Attachment.(record) [200, {"Content-Type" => .content_type}, .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 |