Class: Rack::Hard::Copy

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/rack/hard/copy.rb,
lib/rack/hard/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Method Summary collapse

Methods included from Util

#expired?, #generate_path_from, #http_headers, #ignored?, #make_dir, #setup_variables

Constructor Details

#initialize(app, opts = {}) ⇒ Copy

Returns a new instance of Copy.



9
10
11
12
13
14
15
16
17
18
# File 'lib/rack/hard/copy.rb', line 9

def initialize(app, opts={})
  @app             = app
  opts[:store]   ||= "./static"
  opts[:ignores] ||= []
  opts[:headers] ||= false
  opts[:timeout] ||= 600
  @options         = opts

  make_dir(@options[:store])
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rack/hard/copy.rb', line 20

def call(env)
  return @app.call(env) if     ignored?(@options[:ignores], env["PATH_INFO"].to_s)
  return @app.call(env) unless env["REQUEST_METHOD"] == "GET"

  logger = env['rack.logger']||nil
  path   = generate_path_from(@options[:store], env['PATH_INFO'].to_s)

  if @options[:timeout] === false || expired?(@options[:timeout], path)
    logger.warn "Rack::Hard::Copy: Warning, Copy without timeout is just a Save." if @options[:timeout] === false
    return Rack::Hard::Save.new(@app, @options).call(env)
  else
    return Rack::Hard::Load.new(@app, @options).call(env)
  end
end