activerecord-nulldb-adapter 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  pkg
2
2
  html
3
+ *.gem
3
4
  .ginger
4
5
  .rvmrc
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{activerecord-nulldb-adapter}
3
- s.version = "0.2.2"
3
+ s.version = "0.2.3"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Avdi Grimm", "Myron Marston"]
@@ -24,6 +24,8 @@ Gem::Specification.new do |s|
24
24
  "lib/activerecord-nulldb-adapter.rb",
25
25
  "lib/active_record/connection_adapters/nulldb_adapter.rb",
26
26
  "lib/nulldb/arel_compiler.rb",
27
+ "lib/nulldb/rails.rb",
28
+ "lib/nulldb/core.rb",
27
29
  "lib/nulldb_rspec.rb",
28
30
  "lib/tasks/database.rake",
29
31
  "spec/nulldb_spec.rb",
@@ -0,0 +1,37 @@
1
+ require 'active_record/connection_adapters/nulldb_adapter'
2
+
3
+ module NullDB
4
+ class Configuration < Struct.new(:project_root); end
5
+
6
+ class << self
7
+ def configure
8
+ @configuration = Configuration.new.tap {|c| yield c}
9
+ end
10
+
11
+ def configuration
12
+ if @configuration.nil?
13
+ raise "NullDB not configured. Require a framework, ex 'nulldb/rails'"
14
+ end
15
+
16
+ @configuration
17
+ end
18
+
19
+ def nullify(options={})
20
+ begin
21
+ @prev_connection = ActiveRecord::Base.connection_pool.try(:spec)
22
+ rescue ActiveRecord::ConnectionNotEstablished
23
+ end
24
+ ActiveRecord::Base.establish_connection(options.merge(:adapter => :nulldb))
25
+ end
26
+
27
+ def restore
28
+ if @prev_connection
29
+ ActiveRecord::Base.establish_connection(@prev_connection.config)
30
+ end
31
+ end
32
+
33
+ def checkpoint
34
+ ActiveRecord::Base.connection.checkpoint!
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ require 'nulldb/core'
2
+
3
+ # Need to defer calling Rails.root because when bundler loads, Rails.root is nil
4
+ NullDB.configure {|ndb| def ndb.project_root;Rails.root;end}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-nulldb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -66,6 +66,8 @@ files:
66
66
  - lib/activerecord-nulldb-adapter.rb
67
67
  - lib/active_record/connection_adapters/nulldb_adapter.rb
68
68
  - lib/nulldb/arel_compiler.rb
69
+ - lib/nulldb/rails.rb
70
+ - lib/nulldb/core.rb
69
71
  - lib/nulldb_rspec.rb
70
72
  - lib/tasks/database.rake
71
73
  - spec/nulldb_spec.rb