dm-ambition 1.0.0 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +77 -0
- data/LICENSE +1 -1
- data/README.rdoc +15 -6
- data/Rakefile +3 -9
- data/TODO +13 -0
- data/dm-ambition.gemspec +70 -56
- data/lib/dm-ambition/collection.rb +18 -48
- data/lib/dm-ambition/model.rb +1 -0
- data/lib/dm-ambition/query/filter_processor.rb +149 -255
- data/lib/dm-ambition/query.rb +4 -5
- data/lib/dm-ambition/version.rb +1 -1
- data/lib/dm-ambition.rb +7 -0
- data/spec/public/collection_spec.rb +102 -68
- data/spec/public/model_spec.rb +8 -11
- data/spec/public/shared/filter_shared_spec.rb +45 -9
- data/spec/semipublic/query_spec.rb +283 -67
- data/spec/spec_helper.rb +9 -41
- data/tasks/local_gemfile.rake +16 -0
- data/tasks/spec.rake +0 -3
- metadata +82 -63
- data/.gitignore +0 -35
data/Gemfile
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
DATAMAPPER = 'git://github.com/datamapper'
|
4
|
+
DM_VERSION = '~> 1.0.2'
|
5
|
+
|
6
|
+
group :runtime do
|
7
|
+
|
8
|
+
if ENV['EXTLIB']
|
9
|
+
gem 'extlib', '~> 0.9.15', SOURCE => "#{DATAMAPPER}/extlib#{REPO_POSTFIX}", :require => nil
|
10
|
+
else
|
11
|
+
gem 'activesupport', '~> 3.0.4', :require => nil
|
12
|
+
gem 'i18n', '~> 0.5.0'
|
13
|
+
end
|
14
|
+
|
15
|
+
gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
|
16
|
+
gem 'ParseTree', '~> 3.0.7', :platforms => :mri_18
|
17
|
+
gem 'ruby2ruby', '~> 1.2.5'
|
18
|
+
gem 'sourcify', '~> 0.4.2'
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
group :development do
|
23
|
+
|
24
|
+
gem 'dm-migrations', DM_VERSION, :git => "#{DATAMAPPER}/dm-migrations.git"
|
25
|
+
gem 'jeweler', '~> 1.5.2'
|
26
|
+
gem 'rake', '~> 0.8.7'
|
27
|
+
gem 'rspec', '~> 1.3.1'
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
platforms :mri_18 do
|
32
|
+
group :quality do
|
33
|
+
|
34
|
+
gem 'metric_fu', '~> 1.3'
|
35
|
+
gem 'rcov', '~> 0.9.9'
|
36
|
+
gem 'reek', '~> 1.2.8'
|
37
|
+
gem 'roodi', '~> 2.1'
|
38
|
+
gem 'yard', '~> 0.6'
|
39
|
+
gem 'yardstick', '~> 0.2'
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
group :datamapper do
|
45
|
+
|
46
|
+
adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
|
47
|
+
adapters = adapters.to_s.tr(',', ' ').split.uniq - %w[ in_memory ]
|
48
|
+
|
49
|
+
DO_VERSION = '~> 0.10.2'
|
50
|
+
DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
|
51
|
+
|
52
|
+
if (do_adapters = DM_DO_ADAPTERS & adapters).any?
|
53
|
+
options = {}
|
54
|
+
options[:git] = "#{DATAMAPPER}/do.git" if ENV['DO_GIT'] == 'true'
|
55
|
+
|
56
|
+
gem 'data_objects', DO_VERSION, options.dup
|
57
|
+
|
58
|
+
do_adapters.each do |adapter|
|
59
|
+
adapter = 'sqlite3' if adapter == 'sqlite'
|
60
|
+
gem "do_#{adapter}", DO_VERSION, options.dup
|
61
|
+
end
|
62
|
+
|
63
|
+
gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
|
64
|
+
end
|
65
|
+
|
66
|
+
adapters.each do |adapter|
|
67
|
+
gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
|
68
|
+
end
|
69
|
+
|
70
|
+
plugins = ENV['PLUGINS'] || ENV['PLUGIN']
|
71
|
+
plugins = plugins.to_s.tr(',', ' ').split.push('dm-migrations').uniq
|
72
|
+
|
73
|
+
plugins.each do |plugin|
|
74
|
+
gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -7,9 +7,8 @@ accessing DataMapper models.
|
|
7
7
|
|
8
8
|
With Rubygems:
|
9
9
|
|
10
|
-
$
|
10
|
+
$ gem install dm-ambition
|
11
11
|
$ irb -rubygems
|
12
|
-
>> require 'dm-core'
|
13
12
|
>> require 'dm-ambition'
|
14
13
|
=> true
|
15
14
|
|
@@ -17,12 +16,19 @@ With git and local working copy:
|
|
17
16
|
|
18
17
|
$ git clone git://github.com/dkubb/dm-ambition.git
|
19
18
|
$ cd dm-ambition
|
20
|
-
$ rake
|
19
|
+
$ rake install
|
21
20
|
$ irb -rubygems
|
22
|
-
>> require 'dm-core'
|
23
21
|
>> require 'dm-ambition'
|
24
22
|
=> true
|
25
23
|
|
24
|
+
== Testing
|
25
|
+
|
26
|
+
The simplest way to test is with Bundler since it handles all dependencies:
|
27
|
+
|
28
|
+
$ rake local_gemfile
|
29
|
+
$ BUNDLE_GEMFILE="Gemfile.local" ADAPTER="in_memory" bundle install --without=quality --relock
|
30
|
+
$ BUNDLE_GEMFILE="Gemfile.local" ADAPTER="in_memory" bundle exec rake spec
|
31
|
+
|
26
32
|
== Examples
|
27
33
|
|
28
34
|
# with == operator
|
@@ -67,9 +73,12 @@ With git and local working copy:
|
|
67
73
|
# with double-negated conditions
|
68
74
|
User.select { |u| !(!(u.id == 1)) }
|
69
75
|
|
70
|
-
# with receiver
|
76
|
+
# with matching from receiver
|
71
77
|
User.select { |u| u == user }
|
72
78
|
|
79
|
+
# with matching to receiver
|
80
|
+
User.select { |u| user == u }
|
81
|
+
|
73
82
|
# using send on receiver
|
74
83
|
User.select { |u| u.send(:name) == 'Dan Kubb' }
|
75
84
|
|
@@ -96,7 +105,7 @@ With git and local working copy:
|
|
96
105
|
|
97
106
|
== License
|
98
107
|
|
99
|
-
Copyright (c)
|
108
|
+
Copyright (c) 2011 Dan Kubb
|
100
109
|
|
101
110
|
Permission is hereby granted, free of charge, to any person obtaining
|
102
111
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake'
|
|
4
4
|
require File.expand_path('../lib/dm-ambition/version', __FILE__)
|
5
5
|
|
6
6
|
begin
|
7
|
-
gem 'jeweler', '~> 1.
|
7
|
+
gem 'jeweler', '~> 1.5.2'
|
8
8
|
require 'jeweler'
|
9
9
|
|
10
10
|
Jeweler::Tasks.new do |gem|
|
@@ -14,19 +14,13 @@ begin
|
|
14
14
|
gem.email = 'dan.kubb@gmail.com'
|
15
15
|
gem.homepage = 'http://github.com/dkubb/%s' % gem.name
|
16
16
|
gem.authors = [ 'Dan Kubb' ]
|
17
|
+
gem.has_rdoc = 'yard'
|
17
18
|
|
18
19
|
gem.version = DataMapper::Ambition::VERSION
|
19
20
|
|
20
|
-
gem.required_ruby_version = '~> 1.8.
|
21
|
+
gem.required_ruby_version = '~> 1.8.7'
|
21
22
|
|
22
23
|
gem.rubyforge_project = 'dm-ambition'
|
23
|
-
|
24
|
-
gem.add_dependency 'dm-core', '~> 1.0.0'
|
25
|
-
gem.add_dependency 'ParseTree', '~> 3.0.5'
|
26
|
-
gem.add_dependency 'ruby2ruby', '~> 1.2.4'
|
27
|
-
|
28
|
-
gem.add_development_dependency 'dm-migrations', '~> 1.0.0'
|
29
|
-
gem.add_development_dependency 'rspec', '~> 1.3'
|
30
24
|
end
|
31
25
|
|
32
26
|
Jeweler::GemcutterTasks.new
|
data/TODO
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
* Heckle the methods to make sure that the specs cover all branches
|
2
|
+
within the code.
|
3
|
+
* The purpose of this is to make sure we have good test cases
|
4
|
+
to use with a Veritas port in the future.
|
5
|
+
|
6
|
+
* Refactor specs to use one spec file per public method
|
7
|
+
|
8
|
+
* Add to Model and Collection:
|
9
|
+
* Add #empty?
|
10
|
+
* Add #any? (handle with and without block)
|
11
|
+
* Add #all? (handle with and without block)
|
12
|
+
* Add #none? (handle with and without block) (add to LazyArray for < 1.9)
|
13
|
+
* Add #one? (handle with and without block) (add to LazyArray for < 1.9)
|
data/dm-ambition.gemspec
CHANGED
@@ -1,90 +1,104 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-ambition}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.1.0.rc1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dan Kubb"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-02-28}
|
13
13
|
s.description = %q{DataMapper plugin providing an Ambition-like API}
|
14
14
|
s.email = %q{dan.kubb@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
18
|
-
|
17
|
+
"README.rdoc",
|
18
|
+
"TODO"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".document",
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE",
|
24
|
+
"Manifest.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"TODO",
|
28
|
+
"dm-ambition.gemspec",
|
29
|
+
"lib/dm-ambition.rb",
|
30
|
+
"lib/dm-ambition/collection.rb",
|
31
|
+
"lib/dm-ambition/model.rb",
|
32
|
+
"lib/dm-ambition/query.rb",
|
33
|
+
"lib/dm-ambition/query/filter_processor.rb",
|
34
|
+
"lib/dm-ambition/version.rb",
|
35
|
+
"spec/public/collection_spec.rb",
|
36
|
+
"spec/public/model_spec.rb",
|
37
|
+
"spec/public/shared/filter_shared_spec.rb",
|
38
|
+
"spec/rcov.opts",
|
39
|
+
"spec/semipublic/query_spec.rb",
|
40
|
+
"spec/spec.opts",
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"tasks/ci.rake",
|
43
|
+
"tasks/clean.rake",
|
44
|
+
"tasks/heckle.rake",
|
45
|
+
"tasks/local_gemfile.rake",
|
46
|
+
"tasks/metrics.rake",
|
47
|
+
"tasks/spec.rake",
|
48
|
+
"tasks/yard.rake",
|
49
|
+
"tasks/yardstick.rake"
|
49
50
|
]
|
50
51
|
s.homepage = %q{http://github.com/dkubb/dm-ambition}
|
51
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
52
52
|
s.require_paths = ["lib"]
|
53
|
-
s.required_ruby_version = Gem::Requirement.new("~> 1.8.
|
53
|
+
s.required_ruby_version = Gem::Requirement.new("~> 1.8.7")
|
54
54
|
s.rubyforge_project = %q{dm-ambition}
|
55
|
-
s.rubygems_version = %q{1.
|
55
|
+
s.rubygems_version = %q{1.5.2}
|
56
56
|
s.summary = %q{DataMapper plugin providing an Ambition-like API}
|
57
57
|
s.test_files = [
|
58
58
|
"spec/public/collection_spec.rb",
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
"spec/public/model_spec.rb",
|
60
|
+
"spec/public/shared/filter_shared_spec.rb",
|
61
|
+
"spec/semipublic/query_spec.rb",
|
62
|
+
"spec/spec_helper.rb"
|
63
63
|
]
|
64
64
|
|
65
65
|
if s.respond_to? :specification_version then
|
66
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
66
|
s.specification_version = 3
|
68
67
|
|
69
68
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
70
|
-
s.add_runtime_dependency(%q<
|
71
|
-
s.add_runtime_dependency(%q<
|
72
|
-
s.add_runtime_dependency(%q<
|
73
|
-
s.
|
74
|
-
s.
|
69
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.4"])
|
70
|
+
s.add_runtime_dependency(%q<i18n>, ["~> 0.5.0"])
|
71
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.2"])
|
72
|
+
s.add_runtime_dependency(%q<ParseTree>, ["~> 3.0.7"])
|
73
|
+
s.add_runtime_dependency(%q<ruby2ruby>, ["~> 1.2.5"])
|
74
|
+
s.add_runtime_dependency(%q<sourcify>, ["~> 0.4.2"])
|
75
|
+
s.add_development_dependency(%q<dm-migrations>, ["~> 1.0.2"])
|
76
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
77
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
78
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
|
75
79
|
else
|
76
|
-
s.add_dependency(%q<
|
77
|
-
s.add_dependency(%q<
|
78
|
-
s.add_dependency(%q<
|
79
|
-
s.add_dependency(%q<
|
80
|
-
s.add_dependency(%q<
|
80
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
81
|
+
s.add_dependency(%q<i18n>, ["~> 0.5.0"])
|
82
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.2"])
|
83
|
+
s.add_dependency(%q<ParseTree>, ["~> 3.0.7"])
|
84
|
+
s.add_dependency(%q<ruby2ruby>, ["~> 1.2.5"])
|
85
|
+
s.add_dependency(%q<sourcify>, ["~> 0.4.2"])
|
86
|
+
s.add_dependency(%q<dm-migrations>, ["~> 1.0.2"])
|
87
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
88
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
89
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.1"])
|
81
90
|
end
|
82
91
|
else
|
83
|
-
s.add_dependency(%q<
|
84
|
-
s.add_dependency(%q<
|
85
|
-
s.add_dependency(%q<
|
86
|
-
s.add_dependency(%q<
|
87
|
-
s.add_dependency(%q<
|
92
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
93
|
+
s.add_dependency(%q<i18n>, ["~> 0.5.0"])
|
94
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.2"])
|
95
|
+
s.add_dependency(%q<ParseTree>, ["~> 3.0.7"])
|
96
|
+
s.add_dependency(%q<ruby2ruby>, ["~> 1.2.5"])
|
97
|
+
s.add_dependency(%q<sourcify>, ["~> 0.4.2"])
|
98
|
+
s.add_dependency(%q<dm-migrations>, ["~> 1.0.2"])
|
99
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
100
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
101
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.1"])
|
88
102
|
end
|
89
103
|
end
|
90
104
|
|
@@ -1,73 +1,43 @@
|
|
1
|
-
# TODO: update Collection#select in dm-core to return a Collection
|
2
|
-
# TODO: update Collection#reject in dm-core to return a Collection
|
3
|
-
|
4
1
|
module DataMapper
|
5
2
|
module Ambition
|
6
3
|
module Collection
|
7
4
|
def self.included(base)
|
8
|
-
base.send(:alias_method, :find_all, :select)
|
9
5
|
base.send(:alias_method, :find, :detect)
|
6
|
+
base.send(:alias_method, :find_all, :select)
|
10
7
|
end
|
11
8
|
|
12
|
-
# TODO: add empty?
|
13
|
-
# TODO: add any? (handle with and without block)
|
14
|
-
# TODO: add all? (handle with and without block)
|
15
|
-
# TODO: add none? (handle with and without block) (add to LazyArray for < 1.9)
|
16
|
-
# TODO: add one? (handle with and without block) (add to LazyArray for < 1.9)
|
17
|
-
|
18
9
|
# TODO: document this
|
19
10
|
# @api public
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
if loaded?
|
24
|
-
new_collection(query, super)
|
25
|
-
else
|
26
|
-
collection = all(query)
|
27
|
-
|
28
|
-
if head.any?
|
29
|
-
collection.unshift(*head.select(&block))
|
30
|
-
end
|
31
|
-
|
32
|
-
if tail.any?
|
33
|
-
collection.concat(tail.select(&block))
|
34
|
-
end
|
35
|
-
|
36
|
-
collection
|
37
|
-
end
|
11
|
+
def detect(&block)
|
12
|
+
return super if loaded?
|
13
|
+
head.detect(&block) || first(query.filter(&block))
|
38
14
|
end
|
39
15
|
|
40
16
|
# TODO: document this
|
41
17
|
# @api public
|
42
|
-
def
|
43
|
-
|
44
|
-
super
|
45
|
-
else
|
46
|
-
head.detect(&block) || first(query.filter(&block))
|
47
|
-
end
|
18
|
+
def select(&block)
|
19
|
+
filter_collection(:&, block) { super }
|
48
20
|
end
|
49
21
|
|
50
22
|
# TODO: document this
|
51
23
|
# @api public
|
52
24
|
def reject(&block)
|
53
|
-
|
54
|
-
|
55
|
-
if loaded?
|
56
|
-
new_collection(query, super)
|
57
|
-
else
|
58
|
-
collection = all(query)
|
25
|
+
filter_collection(:-, block) { super }
|
26
|
+
end
|
59
27
|
|
60
|
-
|
61
|
-
collection.unshift(*head.reject(&block))
|
62
|
-
end
|
28
|
+
private
|
63
29
|
|
64
|
-
|
65
|
-
|
66
|
-
|
30
|
+
# @api private
|
31
|
+
def filter_collection(operation, block)
|
32
|
+
new_query = query.filter(&block)
|
33
|
+
return new_collection(new_query, yield) if loaded?
|
67
34
|
|
68
|
-
|
69
|
-
|
35
|
+
collection = send(operation, all(new_query))
|
36
|
+
collection.unshift(*head.send(operation, head.select(&block)))
|
37
|
+
collection.concat(tail.send(operation, tail.select(&block)))
|
38
|
+
collection
|
70
39
|
end
|
40
|
+
|
71
41
|
end # module Collection
|
72
42
|
end # module Ambition
|
73
43
|
end # module DataMapper
|