Permalink
Browse files

Add the DataMapper adapter

  • Loading branch information...
1 parent 472f1cd commit 22acea1575f312630a25dacf3085aba97a221c94 @laserlemon committed Jun 30, 2012
View
@@ -8,3 +8,4 @@ gemspec :name => 'periscope'
gemspec :name => 'periscope-activerecord'
gemspec :name => 'periscope-mongo_mapper'
gemspec :name => 'periscope-mongoid'
+gemspec :name => 'periscope-data_mapper'
View
@@ -9,6 +9,7 @@ Periscope sits on top of your favorite ORM. Currently, the following ORMs are su
* ActiveRecord ([periscope-activerecord](https://rubygems.org/gems/periscope-activerecord))
* MongoMapper ([periscope-mongo_mapper](https://rubygems.org/gems/periscope-mongo_mapper))
* Mongoid ([periscope-mongoid](https://rubygems.org/gems/periscope-mongoid))
+* DataMapper ([periscope-data_mapper](https://rubygems.org/gems/periscope-data_mapper))
Simply add the gem to your bundle and you're off!
View
@@ -5,8 +5,9 @@ Bundler::GemHelper.install_tasks(:name => 'periscope')
Bundler::GemHelper.install_tasks(:name => 'periscope-activerecord')
Bundler::GemHelper.install_tasks(:name => 'periscope-mongo_mapper')
Bundler::GemHelper.install_tasks(:name => 'periscope-mongoid')
+Bundler::GemHelper.install_tasks(:name => 'periscope-data_mapper')
-ADAPTERS = %w(active_record mongo_mapper mongoid)
+ADAPTERS = %w(active_record mongo_mapper mongoid data_mapper)
ADAPTERS.each do |adapter|
desc "Run RSpec code examples for #{adapter} adapter"
@@ -0,0 +1 @@
+require 'periscope/adapters/data_mapper'
@@ -0,0 +1,18 @@
+require 'periscope'
+require 'data_mapper'
+
+module Periscope
+ module Adapters
+ module DataMapper
+ include Periscope
+
+ private
+
+ def periscope_default_scope
+ all
+ end
+ end
+ end
+end
+
+DataMapper::Model.send(:include, Periscope::Adapters::DataMapper)
@@ -0,0 +1,30 @@
+# encoding: utf-8
+
+Gem::Specification.new do |gem|
+ gem.name = 'periscope-data_mapper'
+ gem.version = '1.0.0'
+
+ gem.authors = ['Steve Richert']
+ gem.email = ['steve.richert@gmail.com']
+ gem.description = %(Push your DataMapper models' scopes up to the surface)
+ gem.summary = gem.description
+ gem.homepage = 'https://github.com/laserlemon/periscope'
+
+ gem.add_dependency 'data_mapper', '~> 1.0'
+ gem.add_dependency 'periscope', '~> 1.0'
+
+ gem.add_development_dependency 'database_cleaner', '~> 0.8'
+ gem.add_development_dependency 'dm-sqlite-adapter', '~> 1.0'
+ gem.add_development_dependency 'factory_girl', '>= 2', '< 4'
+ gem.add_development_dependency 'rake', '~> 0.9'
+ gem.add_development_dependency 'rspec', '~> 2.0'
+ gem.add_development_dependency 'sqlite3'
+
+ gem.files = %w(
+ LICENSE
+ lib/periscope-data_mapper.rb
+ lib/periscope/adapters/data_mapper.rb
+ periscope-data_mapper.gemspec
+ README.md
+ )
+end
@@ -0,0 +1,8 @@
+require 'spec_helper'
+
+describe 'Periscope::Adapters::DataMapper', :adapter => 'data_mapper' do
+ let(:model){ User }
+
+ include_examples 'periscopic'
+ include_examples 'databasic'
+end
@@ -1,6 +1,6 @@
require 'database_cleaner'
-DatabaseCleaner.strategy = :truncation
+DatabaseCleaner['active_record'].strategy = :truncation
RSpec.configure do |config|
config.before do
@@ -0,0 +1,3 @@
+require 'data_mapper'
+
+DataMapper.setup(:default, 'sqlite::memory:')
@@ -0,0 +1,13 @@
+require 'database_cleaner'
+
+DatabaseCleaner['data_mapper'].strategy = :truncation
+
+RSpec.configure do |config|
+ config.before do
+ DatabaseCleaner.clean
+ end
+end
+
+at_exit do
+ DatabaseCleaner.clean
+end
@@ -0,0 +1,12 @@
+require 'factory_girl'
+
+RSpec.configure do |config|
+ config.include(FactoryGirl::Syntax::Methods)
+end
+
+FactoryGirl.define do
+ factory :user do
+ gender{ %(male female)[rand(2)] }
+ salary{ rand(1_000_001) }
+ end
+end
@@ -0,0 +1,5 @@
+RSpec.configure do |config|
+ config.before do
+ User.instance_variable_set(:@periscope_options, nil)
+ end
+end
@@ -0,0 +1,3 @@
+require File.expand_path('../user', __FILE__)
+
+User.auto_migrate!
@@ -0,0 +1,27 @@
+require File.expand_path('../connection', __FILE__)
+
+class User
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :gender, String
+ property :salary, Integer
+
+ def self.male
+ all(:gender => 'male')
+ end
+
+ def self.female
+ all(:gender => 'female')
+ end
+
+ def self.gender(gender)
+ all(:gender => gender)
+ end
+
+ def self.makes(salary)
+ all(:salary.gte => salary)
+ end
+end
+
+DataMapper.finalize
@@ -1,6 +1,6 @@
require 'database_cleaner'
-DatabaseCleaner.strategy = :truncation
+DatabaseCleaner['mongo_mapper'].strategy = :truncation
RSpec.configure do |config|
config.before do
@@ -1,6 +1,6 @@
require 'database_cleaner'
-DatabaseCleaner.strategy = :truncation
+DatabaseCleaner['mongoid'].strategy = :truncation
RSpec.configure do |config|
config.before do

0 comments on commit 22acea1

Please sign in to comment.