Class: Redirect::App

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

Defined Under Namespace

Classes: StaticFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*redirects) ⇒ App

Returns a new instance of App.


28
29
30
31
32
# File 'lib/redirect/app.rb', line 28

def initialize(*redirects)
  @redirects = redirects.collect do |r|
    Data.new(*r)
  end
end

Instance Attribute Details

#public_dirObject

Returns the value of attribute public_dir


26
27
28
# File 'lib/redirect/app.rb', line 26

def public_dir
  @public_dir
end

#redirectsObject (readonly)

Returns the value of attribute redirects


25
26
27
# File 'lib/redirect/app.rb', line 25

def redirects
  @redirects
end

Instance Method Details

#call(env) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/redirect/app.rb', line 34

def call(env)
  @env = env
  @request = Rack::Request.new(env)
  if static_file.available?
    return static_response
  end
  if request.fullpath == '/sitemap.xml'
    return sitemap_response
  end
  # if request.fullpath == '/' && index_file.available?
    # return index_response
  # end
  @redirects.each do |r|
    if r.matches?(request.fullpath)
      return redirects_response(r)
    end
  end
  not_found_response
end