Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Define a method for each available adapter so you can query what DB i…

…s being used.

Signed-off-by: Ryan Tomayko <rtomayko@gmail.com>
  • Loading branch information...
commit b38571b434c445522012807eb6c43b6f0f7cebb7 1 parent a7fbe88
@dylanegan dylanegan authored committed
Showing with 16 additions and 9 deletions.
  1. +4 −9 lib/sinatra/sequel.rb
  2. +12 −0 spec/spec_sinatra_sequel.rb
View
13 lib/sinatra/sequel.rb
@@ -21,15 +21,6 @@ def database
Sequel.connect(database_url)
end
- def sqlite?
- defined?(Sequel::SQLite::Database) && database.kind_of?(Sequel::SQLite::Database)
- end
-
- # TODO: wrong!
- def postgres?
- ! sqlite?
- end
-
def migration(name, &block)
create_migrations_table
return if database[:migrations].filter(:name => name).count > 0
@@ -40,6 +31,10 @@ def migration(name, &block)
end
end
+ Sequel::Database::ADAPTERS.each do |adapter|
+ define_method("#{adapter}?") { @database.database_type == adapter }
+ end
+
protected
def create_migrations_table
View
12 spec/spec_sinatra_sequel.rb
@@ -55,4 +55,16 @@ class MockSinatraApp < Sinatra::Base
@app.migration('this should run once') { fail }
@app.database[:migrations].count.should.equal 1
end
+
+ it 'allows you to query what adapter is being used' do
+ @app.database = 'sqlite://test.db'
+ @app.sqlite?.should.equal true
+ end
+
+
+ it 'exposes a query for all available sequel adapters' do
+ Sequel::Database::ADAPTERS.each do |adapter|
+ @app.should.respond_to "#{adapter}?"
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.