This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
source "http://rubygems.org" | ||
|
||
# case ENV["MODEL_ADAPTER"] | ||
# when nil, "active_record" | ||
# gem "sqlite3" | ||
# gem "activerecord", :require => "active_record" | ||
# gem "with_model" | ||
# when "data_mapper" | ||
# gem "dm-core", "~> 1.0.2" | ||
# gem "dm-sqlite-adapter", "~> 1.0.2" | ||
# gem "dm-migrations", "~> 1.0.2" | ||
# else | ||
# raise "Unknown model adapter: #{ENV["MODEL_ADAPTER"]}" | ||
# end | ||
case ENV["MODEL_ADAPTER"] | ||
when nil, "active_record" | ||
gem "sqlite3" | ||
gem "activerecord", :require => "active_record" | ||
gem "with_model" | ||
when "data_mapper" | ||
gem "dm-core", "~> 1.0.2" | ||
gem "dm-sqlite-adapter", "~> 1.0.2" | ||
gem "dm-migrations", "~> 1.0.2" | ||
when "mongoid" | ||
gem "bson_ext", "~> 1.1" | ||
gem "mongoid", "~> 2.0.0.beta.20" | ||
else | ||
raise "Unknown model adapter: #{ENV["MODEL_ADAPTER"]}" | ||
end | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Xapit | ||
module Client | ||
class AbstractModelAdapter | ||
def self.inherited(subclass) | ||
@@subclasses ||= [] | ||
@@subclasses << subclass | ||
end | ||
|
||
def self.adapter_class(model_class) | ||
@@subclasses.detect { |subclass| subclass.for_class?(model_class) } || DefaultModelAdapter | ||
end | ||
|
||
def self.for_class?(model_class) | ||
false # override in subclass | ||
end | ||
|
||
def initialize(model_class) | ||
@model_class = model_class | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Xapit | ||
module Client | ||
class ActiveRecordAdapter < AbstractModelAdapter | ||
def self.for_class?(model_class) | ||
model_class <= ActiveRecord::Base | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Xapit | ||
module Client | ||
class DefaultModelAdapter < AbstractModelAdapter | ||
# This adapter is used when no matching adapter is found | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
spec/xapit/client/model_adapters/active_record_adapter_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record" | ||
require "spec_helper" | ||
|
||
RSpec.configure do |config| | ||
config.extend WithModel | ||
end | ||
|
||
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") | ||
|
||
describe Xapit::Client::ActiveRecordAdapter do | ||
with_model :article do | ||
table do |t| | ||
t.string "name" | ||
end | ||
end | ||
|
||
it "is only for active record classes" do | ||
Xapit::Client::ActiveRecordAdapter.should_not be_for_class(Object) | ||
Xapit::Client::ActiveRecordAdapter.should be_for_class(Article) | ||
Xapit::Client::AbstractModelAdapter.adapter_class(Article).should == Xapit::Client::ActiveRecordAdapter | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
spec/xapit/client/model_adapters/default_model_adapter_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "spec_helper" | ||
|
||
describe Xapit::Client::DefaultModelAdapter do | ||
it "should be default for generic classes" do | ||
Xapit::Client::DefaultModelAdapter.adapter_class(Object).should == Xapit::Client::DefaultModelAdapter | ||
end | ||
end |