Permalink
Browse files

ORM abstraction layer superfluous as I'm specializing this gem for AR

  • Loading branch information...
1 parent 1f66cef commit 5f4c07f2da03e000dcc4090dc50e7078a6b80c2a @elight committed Mar 15, 2013
Showing with 20 additions and 26 deletions.
  1. +1 −1 lib/edr.rb
  2. +1 −0 lib/edr/ar/.#repository.rb
  3. +0 −17 lib/edr/ar/repository.rb
  4. +16 −6 lib/edr/repository.rb
  5. +2 −2 spec/test_data.rb
View
@@ -6,4 +6,4 @@
require_relative 'edr/model'
require_relative 'edr/ar/data_validator'
-require_relative 'edr/ar/repository'
+
View
@@ -1,17 +0,0 @@
-module Edr
- module AR
- module Repository
- include ::Edr::Repository
-
- def persist model
- data_object = data(model)
- data_object.save!
-
- model.id = data_object.id
- model.send(:repository=, self)
-
- model
- end
- end
- end
-end
View
@@ -3,23 +3,33 @@
module Edr
module Repository
def delete model
- data_class.destroy data(model)
+ data(model).destroy
end
def delete_by_id id
- data_class.destroy(data_class.get!(id))
+ data_class.find(id).destroy
end
def find id
- wrap(data_class.get!(id))
+ wrap(data_class.find(id))
end
def all
- data_class.find_all.map do |data|
+ data_class.all.map do |data|
wrap(data)
end
end
+ def persist model
+ data_object = data(model)
+ data_object.save!
+
+ model.id = data_object.id
+ model.send(:repository=, self)
+
+ model
+ end
+
protected
def wrap data
@@ -35,7 +45,7 @@ def data model
def set_model_class model_class
singleton_class.send :define_method, :data_class do
- Registry.data_class_for(model_class).to_adapter
+ Registry.data_class_for(model_class)
end
singleton_class.send :define_method, :model_class do
@@ -46,7 +56,7 @@ def set_model_class model_class
private
def where attrs
- data_class.find_all(attrs).map do |data|
+ data_class.where(attrs).map do |data|
wrap(data)
end
end
View
@@ -64,7 +64,7 @@ class Item
# STEP4: Define repository to access data
# --------------------------------------------------
module OrderRepository
- extend Edr::AR::Repository
+ extend Edr::Repository
set_model_class Order
@@ -83,7 +83,7 @@ def self.create_item order, attrs
end
module ItemRepository
- extend Edr::AR::Repository
+ extend Edr::Repository
set_model_class Item
def self.create_item order, attrs

0 comments on commit 5f4c07f

Please sign in to comment.