Class: Raxus::Application

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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)
  @options = options
  @headers = {}
  @request_counter = 0

  @options[:files].map! { |file| File.expand_path(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

#bodyObject

Returns the value of attribute body.



17
18
19
# File 'lib/raxus.rb', line 17

def body
  @body
end

#headersObject

Returns the value of attribute headers.



17
18
19
# File 'lib/raxus.rb', line 17

def headers
  @headers
end

#optionsObject

Returns the value of attribute options.



17
18
19
# File 'lib/raxus.rb', line 17

def options
  @options
end

#request_counterObject

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