Class: Refraction

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

Defined Under Namespace

Classes: Request

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Refraction

Returns a new instance of Refraction.



98
99
100
# File 'lib/refraction.rb', line 98

def initialize(app)
  @app = app
end

Class Method Details

.configure(&block) ⇒ Object

class Request



90
91
92
# File 'lib/refraction.rb', line 90

def self.configure(&block)
  @rules = block
end

.rulesObject



94
95
96
# File 'lib/refraction.rb', line 94

def self.rules
  @rules
end

Instance Method Details

#call(env) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/refraction.rb', line 106

def call(env)
  if self.rules
    request = Request.new(env)

    self.rules.call(request)

    case request.action
    when :permanent, :found, :respond
      request.response
    when :rewrite
      env["rack.url_scheme"]  = request.scheme
      env["HTTP_HOST"]        = request.http_host
      env["SERVER_NAME"]      = request.host
      env["HTTP_PORT"]        = request.port if request.port
      env["PATH_INFO"]        = request.path
      env["QUERY_STRING"]     = request.query
      env["REQUEST_URI"]      = request.fullpath
      @app.call(env)
    else
      @app.call(env)
    end
  else
    @app.call(env)
  end
end

#rulesObject



102
103
104
# File 'lib/refraction.rb', line 102

def rules
  self.class.rules
end