Permalink
Browse files

Reorganize Gem and clean up generated files.

Organize files based on the namespace.
Update the old require path to require the new one.
Split out the version into a constant in the code.
Clean up requires in the code and specs.
  • Loading branch information...
tylerhunt committed Jun 20, 2012
1 parent 9bdc225 commit 746ee526554f966b988e70b6f94b5e73b84efc0a
View
@@ -1,6 +1,18 @@
-/Gemfile.lock
-*.sw?
-.DS_Store
+*.gem
+*.rbc
+.bundle
+.config
+.rvmrc
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
coverage
-rdoc
+doc
+lib/bundler/man
pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
View
@@ -1,2 +1,3 @@
-source 'http://rubygems.org'
+source 'https://rubygems.org'
+
gemspec
View
@@ -0,0 +1,3 @@
+#!/usr/bin/env rake
+
+require 'bundler/gem_tasks'
View
@@ -1,46 +1 @@
-module Rack # :nodoc:
- class CanonicalHost
- HTML_TEMPLATE = <<-HTML
- <!DOCTYPE html>
- <html lang="en-US">
- <head><title>301 Moved Permanently</title></head>
- <body>
- <h1>Moved Permanently</h1>
- <p>The document has moved <a href="%s">here</a>.</p>
- </body>
- </html>
- HTML
-
- def initialize(app, host=nil, options={}, &block)
- @app = app
- @host = host
- @block = block
- @ignored_hosts = options[:ignored_hosts] || []
- end
-
- def call(env)
- if url = url(env)
- [
- 301,
- { 'Location' => url, 'Content-Type' => 'text/html' },
- [HTML_TEMPLATE % url]
- ]
- else
- @app.call(env)
- end
- end
-
- def url(env)
- if (host = host(env)) && env['SERVER_NAME'] != host && !@ignored_hosts.include?(env['SERVER_NAME'])
- url = Rack::Request.new(env).url
- url.sub(%r{\A(https?://)(.*?)(:\d+)?(/|$)}, "\\1#{host}\\3/")
- end
- end
- private :url
-
- def host(env)
- @block ? @block.call(env) || @host : @host
- end
- private :host
- end
-end
+require 'rack/canonical_host'
View
@@ -0,0 +1,48 @@
+require 'rack'
+
+module Rack # :nodoc:
+ class CanonicalHost
+ HTML_TEMPLATE = <<-HTML
+ <!DOCTYPE html>
+ <html lang="en-US">
+ <head><title>301 Moved Permanently</title></head>
+ <body>
+ <h1>Moved Permanently</h1>
+ <p>The document has moved <a href="%s">here</a>.</p>
+ </body>
+ </html>
+ HTML
+
+ def initialize(app, host=nil, options={}, &block)
+ @app = app
+ @host = host
+ @block = block
+ @ignored_hosts = options[:ignored_hosts] || []
+ end
+
+ def call(env)
+ if url = url(env)
+ [
+ 301,
+ { 'Location' => url, 'Content-Type' => 'text/html' },
+ [HTML_TEMPLATE % url]
+ ]
+ else
+ @app.call(env)
+ end
+ end
+
+ def url(env)
+ if (host = host(env)) && env['SERVER_NAME'] != host && !@ignored_hosts.include?(env['SERVER_NAME'])
+ url = Rack::Request.new(env).url
+ url.sub(%r{\A(https?://)(.*?)(:\d+)?(/|$)}, "\\1#{host}\\3/")
+ end
+ end
+ private :url
+
+ def host(env)
+ @block ? @block.call(env) || @host : @host
+ end
+ private :host
+ end
+end
@@ -0,0 +1,5 @@
+module Rack
+ class CanonicalHost
+ VERSION = '0.0.3'
+ end
+end
@@ -1,12 +1,17 @@
+require './lib/rack/canonical_host/version'
+
Gem::Specification.new do |gem|
gem.name = 'rack-canonical-host'
- gem.version = '0.0.3'
- gem.summary = %q{Rack middleware for defining a canonical host name.}
- gem.homepage = %q{http://github.com/tylerhunt/rack-canonical-host}
- gem.authors = ['Tyler Hunt']
-
- gem.files = Dir['LICENSE', 'README.rdoc', 'lib/**/*']
+ gem.version = Rack::CanonicalHost::VERSION
+ gem.summary = 'Rack middleware for defining a canonical host name.'
+ gem.homepage = 'http://github.com/tylerhunt/rack-canonical-host'
+ gem.author = 'Tyler Hunt'
gem.add_dependency 'rack', '>= 1.0.0'
gem.add_development_dependency 'rspec', '~> 2.0'
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.require_paths = ['lib']
end
@@ -1,10 +1,5 @@
require 'spec_helper'
-require 'rack'
-require 'uri'
-
-require 'rack-canonical-host'
-
describe Rack::CanonicalHost do
context '#call' do
let(:requested_uri) { URI.parse('http://myapp.com/test/path') }
View
@@ -1,12 +1,7 @@
-# This file was generated by the `rspec --init` command. Conventionally, all
-# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
-# Require this file using `require "spec_helper.rb"` to ensure that it is only
-# loaded once.
-#
-# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+require 'rack/canonical_host'
-Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |support|
- require support
+Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file|
+ require(file)
end
RSpec.configure do |config|

0 comments on commit 746ee52

Please sign in to comment.