Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

shuffling namespacing of things and update docs

  • Loading branch information...
commit 3793d933147034a43656d7e24523fb74e757bd7b 1 parent 295cd5a
@atmos authored
View
6 README.md
@@ -9,9 +9,7 @@ variants your app might 404 on.
Installation
============
- % git clone git://github.com/atmos/rack-redirect.git
- % ... (modify if needed) ...
-
+ % sudo gem install rack-redirect
Deployment
==========
@@ -20,7 +18,7 @@ Your rackup file should look something like this.
require 'rubygems'
require File.join(File.dirname(__FILE__), 'lib', 'rack-redirect')
- use EY::Solo::Rack::Redirect
+ use Rack::EY::Solo::DomainRedirect
run lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['Hello there, gorgeous'] ] }
testing
View
30 lib/app.rb
@@ -1,30 +0,0 @@
-module EY
- module Solo
- module Rack
- class Redirect
- attr_accessor :prefix
- def initialize(app, &block)
- @app = app
- @prefix = nil
- yield self if block_given?
- end
-
- def call(env)
- parts = env['SERVER_NAME'].split('.')
- suffix, chunk, prefix = parts.pop, parts.pop, parts.pop
-
- if prefix == @prefix
- @app.call(env)
- else
- prefix = @prefix ? "#{@prefix}." : ''
- destination = "#{env['rack.url_scheme']}://#{prefix}#{chunk}.#{suffix}"
- destination << "#{env['PATH_INFO']}"
- destination << "?#{env['QUERY_STRING']}" unless env['QUERY_STRING'].empty?
-
- [301, {'Location' => destination}, ['See Ya!']]
- end
- end
- end
- end
- end
-end
View
32 lib/rack-redirect.rb
@@ -1,8 +1,32 @@
require 'rack'
-module EY
- module Solo
- module Rack
+
+module Rack
+ module EY
+ module Solo
+ class DomainRedirect
+ attr_accessor :prefix
+ def initialize(app, &block)
+ @app = app
+ @prefix = nil
+ yield self if block_given?
+ end
+
+ def call(env)
+ parts = env['SERVER_NAME'].split('.')
+ suffix, chunk, prefix = parts.pop, parts.pop, parts.pop
+
+ if prefix == @prefix
+ @app.call(env)
+ else
+ prefix = @prefix ? "#{@prefix}." : ''
+ destination = "#{env['rack.url_scheme']}://#{prefix}#{chunk}.#{suffix}"
+ destination << "#{env['PATH_INFO']}"
+ destination << "?#{env['QUERY_STRING']}" unless env['QUERY_STRING'].empty?
+
+ [301, {'Location' => destination}, ['See Ya!']]
+ end
+ end
+ end
end
end
end
-require File.join(File.dirname(__FILE__),'app')
View
4 spec/rack-redirect_spec.rb
@@ -5,7 +5,7 @@
describe "with a value of 'www'" do
def app
@app ||= Rack::Builder.new do
- use EY::Solo::Rack::Redirect do |app|
+ use Rack::EY::Solo::DomainRedirect do |app|
app.prefix = 'www'
end
run lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['Hello there, gorgeous'] ] }
@@ -44,7 +44,7 @@ def app
describe "without specifying a prefix" do
def app
@app ||= Rack::Builder.new do
- use EY::Solo::Rack::Redirect
+ use Rack::EY::Solo::DomainRedirect
run lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['Hello there, gorgeous'] ] }
end
end
View
2  spec/spec_helper.rb
@@ -1,6 +1,6 @@
ENV['RACK_ENV'] ||= 'test'
require 'rubygems'
-require File.join(File.dirname(__FILE__), '..', 'lib', 'app')
+require File.join(File.dirname(__FILE__), '..', 'lib', 'rack-redirect')
require 'spec'
require 'rack/test'
Please sign in to comment.
Something went wrong with that request. Please try again.