Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasily Mikhaylichenko committed Sep 14, 2012
0 parents commit 27009ef
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm use 1.9.3-p194-perf@slurp --create
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in slurp.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2012 Vasily Mikhaylichenko

MIT License

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.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Slurp

Slurp allows you to temporarily switch to using an in-memory sqlite database with Rails without affecting your main database configuration. It comes in useful when you're doing test driven development and need the tests to run as fast as possible.

## Installation

Add this line to your application's Gemfile:

gem 'slurp'

And then execute:

$ bundle

Or install it yourself as:

$ gem install slurp

## Usage

Prepend your command with `SLURP=1` to get your database loaded in memory.

$ SLURP=1 rspec spec/
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
11 changes: 11 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defaults: &defaults
adapter: sqlite3
database: ":memory:"
verbosity: quiet

development:
<<: *defaults

test:
<<: *defaults

5 changes: 5 additions & 0 deletions lib/slurp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "slurp/version"

module Slurp
require 'slurp/railtie' if defined?(Rails)
end
10 changes: 10 additions & 0 deletions lib/slurp/configuration_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Rails
class Application
class Configuration
def database_configuration
db_config = File.join(File.dirname(__FILE__), '..', '..', 'config', 'database.yml')
YAML::load(ERB.new(IO.read(db_config)).result)
end
end
end
end
20 changes: 20 additions & 0 deletions lib/slurp/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'slurp'
require 'rails'

module Slurp
class Railtie < Rails::Railtie

if ENV['SLURP'] == '1'
config.before_initialize do
load File.join(File.dirname(__FILE__), 'configuration_extension.rb')
end

config.after_initialize do
if Rails.configuration.database_configuration[Rails.env]['database'] == ':memory:'
load "#{Rails.root}/db/schema.rb"
end
end
end

end
end
3 changes: 3 additions & 0 deletions lib/slurp/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Slurp
VERSION = "0.0.2"
end
24 changes: 24 additions & 0 deletions slurp.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'slurp/version'

Gem::Specification.new do |gem|
gem.name = "slurp"
gem.version = Slurp::VERSION
gem.authors = ["Vasily Mikhaylichenko"]
gem.email = ["vasily.mikhaylichenko@gmail.com"]
gem.description = %q{Switch to an in-memory sqlite database in Rails on demand}
gem.summary = %q{Speed up your tests without touching database.yml}
gem.homepage = "http://github.com/vaskas/slurp"

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"]

gem.add_dependency 'rails'
gem.add_dependency 'sqlite3'

gem.add_development_dependency 'pry'
end

0 comments on commit 27009ef

Please sign in to comment.