-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add abstract class - Add spec for abstract method
- Loading branch information
1 parent
06b13c7
commit 444133c
Showing
5 changed files
with
48 additions
and
38 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module ActiveRecord | ||
module Sharding | ||
class AbstractRepository | ||
|
||
private | ||
|
||
def generate_model_for_shard(connection_name) | ||
base_class_name = @base_class.name | ||
class_name = generate_class_name connection_name | ||
|
||
model = Class.new(base_class) do | ||
self.table_name = base_class.table_name | ||
|
||
module_eval <<-RUBY, __FILE__, __LINE__ + 1 | ||
def self.name | ||
"#{base_class_name}::#{class_name}" | ||
end | ||
RUBY | ||
end | ||
|
||
model.class_eval { establish_connection(connection_name) } | ||
model | ||
end | ||
|
||
def generate_class_name(connection_name) | ||
raise NotImplementedError.new("#{self.class.name}.#{__method__} is an abstract method.") | ||
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
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,15 @@ | ||
describe ActiveRecord::Sharding::AbstractRepository do | ||
describe "#generate_class_name" do | ||
let!(:repository) do | ||
Class.new(ActiveRecord::Sharding::AbstractRepository) do | ||
def initialize | ||
generate_class_name "test" | ||
end | ||
end | ||
end | ||
|
||
it "raise NotImplementedError" do | ||
expect { repository.new }.to raise_error NotImplementedError | ||
end | ||
end | ||
end |