Class: Raxus::Application
- Inherits:
-
Object
- Object
- Raxus::Application
- Defined in:
- lib/raxus.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#options ⇒ Object
Returns the value of attribute options.
-
#request_counter ⇒ Object
Returns the value of attribute request_counter.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(options) ⇒ Application
constructor
A new instance of Application.
Constructor Details
#initialize(options) ⇒ Application
Returns a new instance of Application.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/raxus.rb', line 19 def initialize() @options = @headers = {} @request_counter = 0 @options[:files].map! { |file| File.(file) } if @options[:files].size > 1 || File.directory?(@options[:files][0]) @options[:newfile] = compress(@options[:files]) else @options[:newfile] = @options[:files][0] end @body = File.read(@options[:newfile]) @options[:filename] = File.basename(@options[:newfile]) @headers["Content-Type"] = "binary/octet-stream" @headers["Content-Disposition"] = "attachment; filename=\"#{@options[:filename]}\"" @headers["Content-Length"] = @body.size.to_s end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
17 18 19 |
# File 'lib/raxus.rb', line 17 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
17 18 19 |
# File 'lib/raxus.rb', line 17 def headers @headers end |
#options ⇒ Object
Returns the value of attribute options.
17 18 19 |
# File 'lib/raxus.rb', line 17 def @options end |
#request_counter ⇒ Object
Returns the value of attribute request_counter.
17 18 19 |
# File 'lib/raxus.rb', line 17 def request_counter @request_counter end |
Instance Method Details
#call(env) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/raxus.rb', line 40 def call(env) unless @options[:limit] && (@request_counter += 1) > @options[:limit] [200, @headers, [@body]] else [404, {}, ["Download limit exceeded."]] end end |