Permalink
Browse files

Initial version

  • Loading branch information...
0 parents commit a0dcdd94188709bdc9d39ce6acc861f8dd54183a @samuelkadolph committed Dec 15, 2011
Showing with 143 additions and 0 deletions.
  1. +33 −0 .gemspec.rb
  2. +4 −0 .gitignore
  3. +4 −0 Gemfile
  4. +19 −0 LICENSE
  5. +27 −0 README.md
  6. +1 −0 Rakefile
  7. +33 −0 lib/unicorn-rails.rb
  8. +3 −0 lib/unicorn-rails/version.rb
  9. +19 −0 unicorn-rails.gemspec
@@ -0,0 +1,33 @@
+class Readme < String
+ attr_reader :path
+
+ def initialize(path)
+ @path = path
+ super(File.read(self.path))
+ end
+
+ def summary
+ if self =~ /^# (?:\S+)\s+(.+?)\s{2,}/m
+ scrub $1
+ else
+ raise "could not find summary in #{path}"
+ end
+ end
+
+ def description
+ if self =~ /^## Description\s+(.+?)\s{2,}/m
+ scrub $1
+ else
+ raise "could not find description in #{path}"
+ end
+ end
+
+ private
+ def scrub(string)
+ string.delete("\\`").tr("\n", " ").to_s
+ end
+end
+
+def readme(path = File.expand_path("./README.md"))
+ (@readmes ||= {})[path] ||= Readme.new(path)
+end
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in unicorn-rails.gemspec
+gemspec
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2011 by Samuel Kadolph
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,27 @@
+# unicorn-rails
+
+`unicorn-rails` is a simple gem that sets the default server for rack (and rails) to unicorn.
+
+## Description
+
+unicorn-rails overrides the `Rack::Handler.default` method to return `Rack::Handler::Unicorn` which will cause rack (and
+rails) to use unicorn by default.
+
+## Installing
+
+### Recommended
+
+```
+gem install unicorn-rails
+```
+
+### Edge
+
+```
+git clone https://github.com/samuelkadolph/unicorn-rails
+cd unicorn-rails && rake install
+```
+
+## Usage
+
+Add `gem "unicorn-rails"` to your Gemfile and then run `rails s` and it will use unicorn by default.
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
+module UnicornRails
+ require "unicorn-rails/version"
+end
+
+require "unicorn"
+
+module Rack
+ module Handler
+ class Unicorn
+ class << self
+ def run(app, options = {})
+ unicorn_options = {}
+ unicorn_options[:listeners] = ["#{options[:Host]}:#{options[:Port]}"]
+ unicorn_options[:worker_processes] = 3
+
+ if options[:debugger]
+ unicorn_options[:worker_processes] = 1
+ unicorn_options[:timeout] = 120
+ end
+
+ ::Unicorn::Launcher.daemonize!(unicorn_options) if options[:daemonize]
+ ::Unicorn::HttpServer.new(app, unicorn_options).start.join
+ end
+ end
+ end
+
+ register "unicorn", "Rack::Handler::Unicorn"
+
+ def self.default(options = {})
+ Rack::Handler::Unicorn
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module UnicornRails
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,19 @@
+require File.expand_path("../.gemspec", __FILE__)
+require File.expand_path("../lib/unicorn-rails/version", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = "unicorn-rails"
+ s.version = UnicornRails::VERSION
+ s.authors = ["Samuel Kadolph"]
+ s.email = ["samuel@kadolph.com"]
+ s.homepage = "https://github.com/samuelkadolph/unicorn-rails"
+ s.summary = readme.summary
+ s.description = readme.description
+
+ s.required_ruby_version = ">= 1.8.7"
+
+ s.files = Dir["lib/**/*", "LICENSE", "README.md"]
+
+ s.add_dependency "rack"
+ s.add_dependency "unicorn"
+end

0 comments on commit a0dcdd9

Please sign in to comment.