orm_adapter 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,15 @@
1
+ # system crap
1
2
  .DS_Store
3
+
4
+ # local ruby/gems dev stuff
2
5
  .rvmrc
3
6
  .bundle
7
+ Gemfile.lock
8
+
9
+ # built docs
4
10
  .yardoc
5
- pkg
6
11
  doc
12
+
13
+ # built gems
14
+ pkg
15
+ *.gem
data/Gemfile CHANGED
@@ -1,15 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "yard"
4
-
5
- group :test do
6
- gem "activerecord", "~> 3.0.0"
7
- gem "mongoid", "~> 2.0.0.beta.17"
8
- gem "rspec", "~> 2.0.0.rc"
9
- gem "jeweler"
10
- gem "rake"
11
- gem "sqlite3-ruby"
12
- gem "datamapper"
13
- gem "dm-sqlite-adapter"
14
- gem "dm-active_model"
15
- end
3
+ gemspec
@@ -1,20 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ orm_adapter (0.0.4)
5
+
1
6
  GEM
2
7
  remote: http://rubygems.org/
3
8
  specs:
4
- activemodel (3.0.0)
5
- activesupport (= 3.0.0)
9
+ activemodel (3.0.3)
10
+ activesupport (= 3.0.3)
6
11
  builder (~> 2.1.2)
7
- i18n (~> 0.4.1)
8
- activerecord (3.0.0)
9
- activemodel (= 3.0.0)
10
- activesupport (= 3.0.0)
11
- arel (~> 1.0.0)
12
+ i18n (~> 0.4)
13
+ activerecord (3.0.3)
14
+ activemodel (= 3.0.3)
15
+ activesupport (= 3.0.3)
16
+ arel (~> 2.0.2)
12
17
  tzinfo (~> 0.3.23)
13
- activesupport (3.0.0)
14
- addressable (2.2.1)
15
- arel (1.0.1)
16
- activesupport (~> 3.0.0)
17
- bson (1.1)
18
+ activesupport (3.0.3)
19
+ addressable (2.2.2)
20
+ arel (2.0.6)
21
+ bson (1.1.5)
22
+ bson_ext (1.1.5)
18
23
  builder (2.1.2)
19
24
  data_objects (0.10.2)
20
25
  addressable (~> 2.1)
@@ -29,7 +34,7 @@ GEM
29
34
  dm-types (= 1.0.2)
30
35
  dm-validations (= 1.0.2)
31
36
  diff-lcs (1.1.2)
32
- dm-active_model (1.0.2)
37
+ dm-active_model (1.0.3)
33
38
  activemodel (~> 3.0.0)
34
39
  dm-core (~> 1.0.2)
35
40
  dm-aggregates (1.0.2)
@@ -68,52 +73,46 @@ GEM
68
73
  data_objects (= 0.10.2)
69
74
  extlib (0.9.15)
70
75
  fastercsv (1.5.3)
71
- gemcutter (0.6.1)
72
76
  git (1.2.5)
73
- i18n (0.4.1)
74
- jeweler (1.4.0)
75
- gemcutter (>= 0.1.0)
76
- git (>= 1.2.5)
77
- rubyforge (>= 2.0.0)
77
+ i18n (0.5.0)
78
78
  json_pure (1.4.6)
79
- mongo (1.0.9)
80
- bson (>= 1.0.5)
81
- mongoid (2.0.0.beta.19)
79
+ mongo (1.1.5)
80
+ bson (>= 1.1.5)
81
+ mongoid (2.0.0.beta.20)
82
82
  activemodel (~> 3.0)
83
- mongo (= 1.0.9)
83
+ mongo (~> 1.1)
84
84
  tzinfo (~> 0.3.22)
85
85
  will_paginate (~> 3.0.pre)
86
86
  rake (0.8.7)
87
- rspec (2.0.0.rc)
88
- rspec-core (= 2.0.0.rc)
89
- rspec-expectations (= 2.0.0.rc)
90
- rspec-mocks (= 2.0.0.rc)
91
- rspec-core (2.0.0.rc)
92
- rspec-expectations (2.0.0.rc)
93
- diff-lcs (>= 1.1.2)
94
- rspec-mocks (2.0.0.rc)
95
- rspec-core (= 2.0.0.rc)
96
- rspec-expectations (= 2.0.0.rc)
97
- rubyforge (2.0.4)
98
- json_pure (>= 1.1.7)
99
- sqlite3-ruby (1.3.1)
87
+ rspec (2.4.0)
88
+ rspec-core (~> 2.4.0)
89
+ rspec-expectations (~> 2.4.0)
90
+ rspec-mocks (~> 2.4.0)
91
+ rspec-core (2.4.0)
92
+ rspec-expectations (2.4.0)
93
+ diff-lcs (~> 1.1.2)
94
+ rspec-mocks (2.4.0)
95
+ sqlite3-ruby (1.3.2)
100
96
  stringex (1.1.0)
101
97
  tzinfo (0.3.23)
102
98
  uuidtools (2.1.1)
103
99
  will_paginate (3.0.pre2)
104
- yard (0.6.1)
100
+ yard (0.6.4)
105
101
 
106
102
  PLATFORMS
107
103
  ruby
108
104
 
109
105
  DEPENDENCIES
110
- activerecord (~> 3.0.0)
111
- datamapper
112
- dm-active_model
113
- dm-sqlite-adapter
114
- jeweler
115
- mongoid (~> 2.0.0.beta.17)
116
- rake
117
- rspec (~> 2.0.0.rc)
118
- sqlite3-ruby
119
- yard
106
+ activerecord (>= 3.0.0)
107
+ bson_ext (>= 1.1.5)
108
+ bundler (>= 1.0.0)
109
+ datamapper (>= 1.0)
110
+ dm-active_model (>= 1.0)
111
+ dm-sqlite-adapter (>= 1.0)
112
+ git (>= 1.2.5)
113
+ mongoid (>= 2.0.0.beta.20)
114
+ orm_adapter!
115
+ rake (>= 0.8.7)
116
+ rspec (>= 2.4.0)
117
+ sqlite3-ruby (>= 1.3.2)
118
+ yard (>= 0.6.0)
@@ -1,3 +1,9 @@
1
+ == 0.0.4
2
+
3
+ * Adds ability to order results from #find_first and #find_all [Ian White]
4
+ * Rationalise development dependencies and release process [Ian White]
5
+
6
+
1
7
  == 0.0.3
2
8
 
3
9
  * ActiveRecord's OrmAdapter handles non standard foreign key names [Ian White]
@@ -15,9 +15,11 @@ Provides a single point of entry for popular ruby ORMs. Its target audience is
15
15
  user_model.get!(1) # find a record by id
16
16
  user_model.find_first(:name => 'fred') # find first fred
17
17
  user_model.find_all(:name => 'fred') # find all freds
18
+ user_model.find_all(:order => :name) # find all freds, ordered by name
18
19
  user_model.create!(:name => 'fred') # create a fred
19
-
20
20
 
21
+ @see OrmAdapter::Base for more details of the supported API
22
+
21
23
  == Supported ORMs
22
24
 
23
25
  Currently supported ORMs are *ActiveRecord*, *DataMapper* and *MongoId*.
@@ -36,6 +38,14 @@ ORM Adapter will support only basic methods, as +get+, +find_first+, <tt>create!
36
38
  If you need complex queries, we recommend you to subclass ORM Adapters in your plugin and extend it expressing these query conditions as part of your domain logic.
37
39
 
38
40
 
41
+ == Projects using orm_adapter
42
+
43
+ * {devise}[http://github.com/plataformatec/devise]
44
+ * {pickle}[http://github.com/ianwhite/pickle]
45
+
46
+ Get in touch if you want your project added to this list
47
+
48
+
39
49
  == History
40
50
 
41
51
  orm_adapter is an extraction from {pickle}[http://github.com/ianwhite/pickle] by {Ian White}[http://github.com/ianwhite]. Pickle's orm adapter included work by {Daniel Neighman}[http://github.com/hassox], {Josh Bassett}[http://github.com/nullobject], {Marc Lee}[http://github.com/maleko], and {Sebastian Zuchmanski}[http://github.com/sebcioz].
@@ -43,6 +53,17 @@ orm_adapter is an extraction from {pickle}[http://github.com/ianwhite/pickle] by
43
53
  {José Valim}[http://github.com/josevalim] suggested the extraction, and worked on the first release with Ian.
44
54
 
45
55
 
56
+ == Development
57
+
58
+ To run the specs, you can start from the last known good set of gem dependencies in Gemfile.lock.development:
59
+
60
+ git clone http://github.com/ianwhite/orm_adapter
61
+ cd orm_adapter
62
+ cp Gemfile.lock.development Gemfile.lock
63
+ bundle
64
+ bundle exec rake spec
65
+
66
+
46
67
  == Copyright
47
68
 
48
- Copyright (c) 2010 Ian White and José Valim. See LICENSE for details.
69
+ Copyright (c) 2010-2011 Ian White and José Valim. See LICENSE for details.
data/Rakefile CHANGED
@@ -2,38 +2,55 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'rspec/core/rake_task'
4
4
  require 'yard'
5
+ require 'git'
6
+ $:.push File.expand_path("../lib", __FILE__)
7
+ require "orm_adapter/version"
5
8
 
6
- $:.unshift File.expand_path('lib')
7
- require 'orm_adapter/version'
8
-
9
- task :spec => :check_dependencies
10
9
  task :default => :spec
11
10
 
12
- desc "Run the specs"
13
11
  RSpec::Core::RakeTask.new(:spec)
14
12
 
15
- begin
16
- require 'jeweler'
17
- Jeweler::Tasks.new do |gem|
18
- gem.name = "orm_adapter"
19
- gem.version = OrmAdapter::VERSION
20
- gem.summary = %Q{Provides a single point of entry for using basic features of ruby ORMs}
21
- gem.description = %Q{Provides a single point of entry for using basic features of ruby ORMs}
22
- gem.email = "ian.w.white@gmail.com"
23
- gem.homepage = "http://github.com/ianwhite/orm_adapter"
24
- gem.authors = ["Ian White", "Jose Valim"]
13
+ YARD::Rake::YardocTask.new(:doc) do |t|
14
+ t.files = ['lib/**/*.rb', 'README.rdoc']
15
+ end
16
+
17
+ task :build do
18
+ system "gem build orm_adapter.gemspec"
19
+ end
20
+
21
+ namespace :release do
22
+ task :rubygems => :pre do
23
+ system "gem push orm_adapter-#{OrmAdapter::VERSION}.gem"
25
24
  end
26
- Jeweler::GemcutterTasks.new
27
25
 
28
- namespace :release do
29
- desc "release to github and gemcutter"
30
- task :all => ['release', 'gemcutter:release']
26
+ task :github => :pre do
27
+ tag = "v#{OrmAdapter::VERSION}"
28
+ git = Git.open('.')
29
+
30
+ if (git.tag(tag) rescue nil)
31
+ raise "** repo is already tagged with: #{tag}"
32
+ end
33
+
34
+ git.add_tag(tag)
35
+ git.push('origin', tag)
31
36
  end
32
37
 
33
- rescue LoadError
34
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
35
- end
36
-
37
- YARD::Rake::YardocTask.new(:doc) do |t|
38
- t.files = ['lib/**/*.rb', 'README.rdoc']
39
- end
38
+ task :pre => [:spec, :build] do
39
+ git = Git.open('.')
40
+
41
+ if File.exists?("Gemfile.lock") && File.read("Gemfile.lock") != File.read("Gemfile.lock.development")
42
+ cp "Gemfile.lock", "Gemfile.lock.development"
43
+ raise "** Gemfile.lock.development has been updated, please commit these changes."
44
+ end
45
+
46
+ if (git.status.changed + git.status.added + git.status.deleted).any?
47
+ raise "** repo is not clean, try committing some files"
48
+ end
49
+
50
+ if git.object('HEAD').sha != git.object('origin/master').sha
51
+ raise "** origin does not match HEAD, have you pushed?"
52
+ end
53
+ end
54
+
55
+ task :all => ['release:github', 'release:rubygems']
56
+ end
@@ -35,27 +35,29 @@ class ActiveRecord::Base
35
35
  klass.column_names
36
36
  end
37
37
 
38
- # Get an instance by id of the model
38
+ # @see OrmAdapter::Base#get!
39
39
  def get!(id)
40
40
  klass.find(wrap_key(id))
41
41
  end
42
42
 
43
- # Get an instance by id of the model
43
+ # @see OrmAdapter::Base#get
44
44
  def get(id)
45
45
  klass.first :conditions => { klass.primary_key => wrap_key(id) }
46
46
  end
47
47
 
48
- # Find the first instance matching conditions
49
- def find_first(conditions)
50
- klass.first :conditions => conditions_to_fields(conditions)
48
+ # @see OrmAdapter::Base#find_first
49
+ def find_first(options)
50
+ conditions, order = extract_conditions_and_order!(options)
51
+ klass.first :conditions => conditions_to_fields(conditions), :order => order_clause(order)
51
52
  end
52
53
 
53
- # Find all models matching conditions
54
- def find_all(conditions)
55
- klass.all :conditions => conditions_to_fields(conditions)
54
+ # @see OrmAdapter::Base#find_all
55
+ def find_all(options)
56
+ conditions, order = extract_conditions_and_order!(options)
57
+ klass.all :conditions => conditions_to_fields(conditions), :order => order_clause(order)
56
58
  end
57
59
 
58
- # Create a model using attributes
60
+ # @see OrmAdapter::Base#create!
59
61
  def create!(attributes)
60
62
  klass.create!(attributes)
61
63
  end
@@ -75,5 +77,9 @@ class ActiveRecord::Base
75
77
  end
76
78
  fields
77
79
  end
80
+
81
+ def order_clause(order)
82
+ order.map {|pair| "#{pair[0]} #{pair[1]}"}.join(",")
83
+ end
78
84
  end
79
85
  end
@@ -23,30 +23,38 @@ module DataMapper
23
23
  klass.properties.map(&:name)
24
24
  end
25
25
 
26
- # Get an instance by id of the model
26
+ # @see OrmAdapter::Base#get!
27
27
  def get!(id)
28
28
  klass.get!(id)
29
29
  end
30
30
 
31
- # Get an instance by id of the model
31
+ # @see OrmAdapter::Base#get
32
32
  def get(id)
33
33
  klass.get(id)
34
34
  end
35
35
 
36
- # Find the first instance matching conditions
37
- def find_first(conditions)
38
- klass.first(conditions)
36
+ # @see OrmAdapter::Base#find_first
37
+ def find_first(options)
38
+ conditions, order = extract_conditions_and_order!(options)
39
+ klass.first :conditions => conditions, :order => order_clause(order)
39
40
  end
40
41
 
41
- # Find all models matching conditions
42
- def find_all(conditions)
43
- klass.all(conditions)
42
+ # @see OrmAdapter::Base#find_all
43
+ def find_all(options)
44
+ conditions, order = extract_conditions_and_order!(options)
45
+ klass.all :conditions => conditions, :order => order_clause(order)
44
46
  end
45
47
 
46
- # Create a model using attributes
48
+ # @see OrmAdapter::Base#create!
47
49
  def create!(attributes)
48
50
  klass.create(attributes)
49
51
  end
52
+
53
+ protected
54
+
55
+ def order_clause(order)
56
+ order.map {|pair| pair.first.send(pair.last)}
57
+ end
50
58
  end
51
59
  end
52
60
  end
@@ -22,27 +22,29 @@ module Mongoid
22
22
  klass.fields.keys
23
23
  end
24
24
 
25
- # Get an instance by id of the model
25
+ # @see OrmAdapter::Base#get!
26
26
  def get!(id)
27
27
  klass.find(wrap_key(id))
28
28
  end
29
29
 
30
- # Get an instance by id of the model
30
+ # @see OrmAdapter::Base#get
31
31
  def get(id)
32
32
  klass.first(:conditions => { :id => wrap_key(id) })
33
33
  end
34
34
 
35
- # Find the first instance matching conditions
36
- def find_first(conditions)
37
- klass.first(:conditions => conditions_to_fields(conditions))
35
+ # @see OrmAdapter::Base#find_first
36
+ def find_first(options)
37
+ conditions, order = extract_conditions_and_order!(options)
38
+ klass.limit(1).where(conditions_to_fields(conditions)).order_by(order).first
38
39
  end
39
40
 
40
- # Find all models matching conditions
41
- def find_all(conditions)
42
- klass.all(:conditions => conditions_to_fields(conditions))
41
+ # @see OrmAdapter::Base#find_all
42
+ def find_all(options)
43
+ conditions, order = extract_conditions_and_order!(options)
44
+ klass.where(conditions_to_fields(conditions)).order_by(order)
43
45
  end
44
46
 
45
- # Create a model with given attributes
47
+ # @see OrmAdapter::Base#create!
46
48
  def create!(attributes)
47
49
  klass.create!(attributes)
48
50
  end
@@ -46,13 +46,30 @@ module OrmAdapter
46
46
  raise NotSupportedError
47
47
  end
48
48
 
49
- # Find the first instance matching conditions
50
- def find_first(conditions)
49
+ # Find the first instance, optionally matching conditions, and specifying order
50
+ #
51
+ # You can call with just conditions, providing a hash
52
+ #
53
+ # User.to_adapter.find_first :name => "Fred", :age => 23
54
+ #
55
+ # Or you can specify :order, and :conditions as keys
56
+ #
57
+ # User.to_adapter.find_first :conditions => {:name => "Fred", :age => 23}
58
+ # User.to_adapter.find_first :order => [:age, :desc]
59
+ # User.to_adapter.find_first :order => :name, :conditions => {:age => 18}
60
+ #
61
+ # When specifying :order, it may be
62
+ # * a single arg e.g. <tt>:order => :name</tt>
63
+ # * a single pair with :asc, or :desc as last, e.g. <tt>:order => [:name, :desc]</tt>
64
+ # * an array of single args or pairs (with :asc or :desc as last), e.g. <tt>:order => [[:name, :asc], [:age, :desc]]</tt>
65
+ #
66
+ def find_first(options)
51
67
  raise NotSupportedError
52
68
  end
53
69
 
54
- # Find all models matching conditions
55
- def find_all(conditions)
70
+ # Find all models, optionally matching conditions, and specifying order
71
+ # @see OrmAdapter::Base#find_first for how to specify order and conditions
72
+ def find_all(options)
56
73
  raise NotSupportedError
57
74
  end
58
75
 
@@ -66,6 +83,31 @@ module OrmAdapter
66
83
  def wrap_key(key)
67
84
  key.is_a?(Array) ? key.first : key
68
85
  end
86
+
87
+ # given an options hash, with optional :conditions and :order keys, returns conditions and normalized order
88
+ def extract_conditions_and_order!(options = {})
89
+ order = normalize_order(options.delete(:order))
90
+ conditions = options.delete(:conditions) || options
91
+ [conditions, order]
92
+ end
93
+
94
+ # given an order argument, returns an array of pairs, with each pair containing the attribute, and :asc or :desc
95
+ def normalize_order(order)
96
+ order = Array(order)
97
+
98
+ if order.length == 2 && !order[0].is_a?(Array) && [:asc, :desc].include?(order[1])
99
+ order = [order]
100
+ else
101
+ order = order.map {|pair| pair.is_a?(Array) ? pair : [pair, :asc] }
102
+ end
103
+
104
+ order.each do |pair|
105
+ pair.length == 2 or raise ArgumentError, "each order clause must be a pair (unknown clause #{pair.inspect})"
106
+ [:asc, :desc].include?(pair[1]) or raise ArgumentError, "order must be specified with :asc or :desc (unknown key #{pair[1].inspect})"
107
+ end
108
+
109
+ order
110
+ end
69
111
  end
70
112
 
71
113
  class NotSupportedError < NotImplementedError
@@ -1,3 +1,3 @@
1
1
  module OrmAdapter
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,66 +1,34 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "orm_adapter/version"
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = %q{orm_adapter}
8
- s.version = "0.0.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
5
+ s.name = "orm_adapter"
6
+ s.version = OrmAdapter::VERSION.dup
7
+ s.platform = Gem::Platform::RUBY
11
8
  s.authors = ["Ian White", "Jose Valim"]
12
- s.date = %q{2010-10-12}
13
- s.description = %q{Provides a single point of entry for using basic features of ruby ORMs}
14
- s.email = %q{ian.w.white@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".gitignore",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "History.txt",
24
- "LICENSE",
25
- "README.rdoc",
26
- "Rakefile",
27
- "lib/orm_adapter.rb",
28
- "lib/orm_adapter/adapters/active_record.rb",
29
- "lib/orm_adapter/adapters/data_mapper.rb",
30
- "lib/orm_adapter/adapters/mongoid.rb",
31
- "lib/orm_adapter/base.rb",
32
- "lib/orm_adapter/to_adapter.rb",
33
- "lib/orm_adapter/version.rb",
34
- "orm_adapter.gemspec",
35
- "spec/orm_adapter/adapters/active_record_spec.rb",
36
- "spec/orm_adapter/adapters/data_mapper_spec.rb",
37
- "spec/orm_adapter/adapters/mongoid_spec.rb",
38
- "spec/orm_adapter/example_app_shared.rb",
39
- "spec/orm_adapter_spec.rb",
40
- "spec/spec_helper.rb"
41
- ]
42
- s.homepage = %q{http://github.com/ianwhite/orm_adapter}
43
- s.rdoc_options = ["--charset=UTF-8"]
44
- s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.3.7}
46
- s.summary = %q{Provides a single point of entry for using basic features of ruby ORMs}
47
- s.test_files = [
48
- "spec/orm_adapter/adapters/active_record_spec.rb",
49
- "spec/orm_adapter/adapters/data_mapper_spec.rb",
50
- "spec/orm_adapter/adapters/mongoid_spec.rb",
51
- "spec/orm_adapter/example_app_shared.rb",
52
- "spec/orm_adapter_spec.rb",
53
- "spec/spec_helper.rb"
54
- ]
9
+ s.description = "Provides a single point of entry for using basic features of ruby ORMs"
10
+ s.summary = "orm_adapter provides a single point of entry for using basic features of popular ruby ORMs. Its target audience is gem authors who want to support many ruby ORMs."
11
+ s.email = "ian.w.white@gmail.com"
12
+ s.homepage = "http://github.com/ianwhite/orm_adapter"
55
13
 
56
- if s.respond_to? :specification_version then
57
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
- s.specification_version = 3
14
+ s.rubyforge_project = "orm_adapter"
15
+ s.required_rubygems_version = ">= 1.3.6"
59
16
 
60
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
- else
62
- end
63
- else
64
- end
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "bundler", ">= 1.0.0"
22
+ s.add_development_dependency "git", ">= 1.2.5"
23
+ s.add_development_dependency "yard", ">= 0.6.0"
24
+ s.add_development_dependency "rake", ">= 0.8.7"
25
+ s.add_development_dependency "activerecord", ">= 3.0.0"
26
+ s.add_development_dependency "mongoid", ">= 2.0.0.beta.20"
27
+ s.add_development_dependency "bson_ext", ">= 1.1.5"
28
+ s.add_development_dependency "rspec", ">= 2.4.0"
29
+ s.add_development_dependency "sqlite3-ruby", ">= 1.3.2"
30
+ s.add_development_dependency "datamapper", ">= 1.0"
31
+ s.add_development_dependency "dm-sqlite-adapter", ">= 1.0"
32
+ s.add_development_dependency "dm-active_model", ">= 1.0"
65
33
  end
66
34
 
@@ -8,14 +8,13 @@ else
8
8
 
9
9
  ActiveRecord::Migration.suppress_messages do
10
10
  ActiveRecord::Schema.define(:version => 0) do
11
- create_table(:users, :force => true) {|t| t.string :name; t.belongs_to :site }
11
+ create_table(:users, :force => true) {|t| t.string :name; t.integer :rating; }
12
12
  create_table(:notes, :force => true) {|t| t.belongs_to :owner, :polymorphic => true }
13
13
  end
14
14
  end
15
15
 
16
16
  module ArOrmSpec
17
17
  class User < ActiveRecord::Base
18
- belongs_to :site, :class_name => "ArOrmSpec::Site"
19
18
  has_many :notes, :as => :owner
20
19
  end
21
20
 
@@ -12,6 +12,7 @@ else
12
12
  include DataMapper::Resource
13
13
  property :id, Serial
14
14
  property :name, String
15
+ property :rating, Integer
15
16
  has n, :notes, :child_key => [:owner_id]
16
17
  end
17
18
 
@@ -13,6 +13,7 @@ else
13
13
  class User
14
14
  include Mongoid::Document
15
15
  field :name
16
+ field :rating
16
17
  has_many_related :notes, :foreign_key => :owner_id, :class_name => 'MongoidOrmSpec::Note'
17
18
  end
18
19
 
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe OrmAdapter::Base do
4
+ subject { OrmAdapter::Base.new(Object) }
5
+
6
+ describe "#extract_conditions_and_order!" do
7
+ let(:conditions) { {:foo => 'bar'} }
8
+ let(:order) { [[:foo, :asc]] }
9
+
10
+ it "(<conditions>) should return [<conditions>, []]" do
11
+ subject.send(:extract_conditions_and_order!, conditions).should == [conditions, []]
12
+ end
13
+
14
+ it "(:conditions => <conditions>) should return [<conditions>, []]" do
15
+ subject.send(:extract_conditions_and_order!, :conditions => conditions).should == [conditions, []]
16
+ end
17
+
18
+ it "(:order => <order>) should return [{}, <order>]" do
19
+ subject.send(:extract_conditions_and_order!, :order => order).should == [{}, order]
20
+ end
21
+
22
+ it "(:conditions => <conditions>, :order => <order>) should return [<conditions>, <order>]" do
23
+ subject.send(:extract_conditions_and_order!, :conditions => conditions, :order => order).should == [conditions, order]
24
+ end
25
+
26
+ describe "#normalize_order" do
27
+ specify "(nil) returns []" do
28
+ subject.send(:normalize_order, nil).should == []
29
+ end
30
+
31
+ specify ":foo returns [[:foo, :asc]]" do
32
+ subject.send(:normalize_order, :foo).should == [[:foo, :asc]]
33
+ end
34
+
35
+ specify "[:foo] returns [[:foo, :asc]]" do
36
+ subject.send(:normalize_order, [:foo]).should == [[:foo, :asc]]
37
+ end
38
+
39
+ specify "[:foo, :desc] returns [[:foo, :desc]]" do
40
+ subject.send(:normalize_order, [:foo, :desc]).should == [[:foo, :desc]]
41
+ end
42
+
43
+ specify "[:foo, [:bar, :asc], [:baz, :desc], :bing] returns [[:foo, :asc], [:bar, :asc], [:baz, :desc], [:bing, :asc]]" do
44
+ subject.send(:normalize_order, [:foo, [:bar, :asc], [:baz, :desc], :bing]).should == [[:foo, :asc], [:bar, :asc], [:baz, :desc], [:bing, :asc]]
45
+ end
46
+
47
+ specify "[[:foo, :wtf]] raises ArgumentError" do
48
+ lambda { subject.send(:normalize_order, [[:foo, :wtf]]) }.should raise_error(ArgumentError)
49
+ end
50
+
51
+ specify "[[:foo, :asc, :desc]] raises ArgumentError" do
52
+ lambda { subject.send(:normalize_order, [[:foo, :asc, :desc]]) }.should raise_error(ArgumentError)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -80,43 +80,81 @@ shared_examples_for "example app with orm_adapter" do
80
80
  end
81
81
  end
82
82
 
83
- describe "#find_first(conditions)" do
84
- it "should return first model matching conditions, if it exists" do
85
- user = create_model(user_class, :name => "Fred")
86
- user_adapter.find_first(:name => "Fred").should == user
87
- end
83
+ describe "#find_first" do
84
+ describe "(conditions)" do
85
+ it "should return first model matching conditions, if it exists" do
86
+ user = create_model(user_class, :name => "Fred")
87
+ user_adapter.find_first(:name => "Fred").should == user
88
+ end
88
89
 
89
- it "should return nil if no conditions match" do
90
- user_adapter.find_first(:name => "Betty").should == nil
91
- end
90
+ it "should return nil if no conditions match" do
91
+ user_adapter.find_first(:name => "Betty").should == nil
92
+ end
92
93
 
93
- it "when conditions contain associated object, should return first model if it exists" do
94
- user = create_model(user_class)
95
- note = create_model(note_class, :owner => user)
96
- note_adapter.find_first(:owner => user).should == note
94
+ it "when conditions contain associated object, should return first model if it exists" do
95
+ user = create_model(user_class)
96
+ note = create_model(note_class, :owner => user)
97
+ note_adapter.find_first(:owner => user).should == note
98
+ end
97
99
  end
98
- end
99
100
 
100
- describe "#find_all(conditions)" do
101
- it "should return only models matching conditions" do
102
- user1 = create_model(user_class, :name => "Fred")
103
- user2 = create_model(user_class, :name => "Fred")
104
- user3 = create_model(user_class, :name => "Betty")
105
- user_adapter.find_all(:name => "Fred").should == [user1, user2]
101
+ describe "(:order => <order array>)" do
102
+ it "should return first model in specified order" do
103
+ user1 = create_model(user_class, :name => "Fred", :rating => 1)
104
+ user2 = create_model(user_class, :name => "Fred", :rating => 2)
105
+ user_adapter.find_first(:order => [:name, [:rating, :desc]]).should == user2
106
+ end
107
+ end
108
+
109
+ describe "(:conditions => <conditions hash>, :order => <order array>)" do
110
+ it "should return first model matching conditions, in specified order" do
111
+ user1 = create_model(user_class, :name => "Fred", :rating => 1)
112
+ user2 = create_model(user_class, :name => "Fred", :rating => 2)
113
+ user_adapter.find_first(:conditions => {:name => "Fred"}, :order => [:rating, :desc]).should == user2
114
+ end
106
115
  end
116
+ end
117
+
118
+ describe "#find_all" do
119
+ describe "(conditions)" do
120
+ it "should return only models matching conditions" do
121
+ user1 = create_model(user_class, :name => "Fred")
122
+ user2 = create_model(user_class, :name => "Fred")
123
+ user3 = create_model(user_class, :name => "Betty")
124
+ user_adapter.find_all(:name => "Fred").should == [user1, user2]
125
+ end
107
126
 
108
- it "should return empty array if no conditions match" do
109
- user_adapter.find_all(:name => "Fred").should == []
127
+ it "should return empty array if no conditions match" do
128
+ user_adapter.find_all(:name => "Fred").should == []
129
+ end
130
+
131
+ it "when conditions contain associated object, should return first model if it exists" do
132
+ user1, user2 = create_model(user_class), create_model(user_class)
133
+ note1 = create_model(note_class, :owner => user1)
134
+ note2 = create_model(note_class, :owner => user2)
135
+ note_adapter.find_all(:owner => user2).should == [note2]
136
+ end
137
+ end
138
+
139
+ describe "(:order => <order array>)" do
140
+ it "should return all models in specified order" do
141
+ user1 = create_model(user_class, :name => "Fred", :rating => 1)
142
+ user2 = create_model(user_class, :name => "Fred", :rating => 2)
143
+ user3 = create_model(user_class, :name => "Betty", :rating => 1)
144
+ user_adapter.find_all(:order => [:name, [:rating, :desc]]).should == [user3, user2, user1]
145
+ end
110
146
  end
111
147
 
112
- it "when conditions contain associated object, should return first model if it exists" do
113
- user1, user2 = create_model(user_class), create_model(user_class)
114
- note1 = create_model(note_class, :owner => user1)
115
- note2 = create_model(note_class, :owner => user2)
116
- note_adapter.find_all(:owner => user2).should == [note2]
148
+ describe "(:conditions => <conditions hash>, :order => <order array>)" do
149
+ it "should return only models matching conditions, in specified order" do
150
+ user1 = create_model(user_class, :name => "Fred", :rating => 1)
151
+ user2 = create_model(user_class, :name => "Fred", :rating => 2)
152
+ user3 = create_model(user_class, :name => "Betty", :rating => 1)
153
+ user_adapter.find_all(:conditions => {:name => "Fred"}, :order => [:rating, :desc]).should == [user2, user1]
154
+ end
117
155
  end
118
156
  end
119
-
157
+
120
158
  describe "#create!(attributes)" do
121
159
  it "should create a model with the passed attributes" do
122
160
  user = user_adapter.create!(:name => "Fred")
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orm_adapter
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 3
9
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ian White
@@ -15,23 +16,212 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-10-12 00:00:00 +01:00
19
+ date: 2011-01-04 00:00:00 +00:00
19
20
  default_executable:
20
- dependencies: []
21
-
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: bundler
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 23
31
+ segments:
32
+ - 1
33
+ - 0
34
+ - 0
35
+ version: 1.0.0
36
+ type: :development
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: git
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 21
47
+ segments:
48
+ - 1
49
+ - 2
50
+ - 5
51
+ version: 1.2.5
52
+ type: :development
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: yard
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 7
63
+ segments:
64
+ - 0
65
+ - 6
66
+ - 0
67
+ version: 0.6.0
68
+ type: :development
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 49
79
+ segments:
80
+ - 0
81
+ - 8
82
+ - 7
83
+ version: 0.8.7
84
+ type: :development
85
+ version_requirements: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: activerecord
88
+ prerelease: false
89
+ requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 7
95
+ segments:
96
+ - 3
97
+ - 0
98
+ - 0
99
+ version: 3.0.0
100
+ type: :development
101
+ version_requirements: *id005
102
+ - !ruby/object:Gem::Dependency
103
+ name: mongoid
104
+ prerelease: false
105
+ requirement: &id006 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 62196427
111
+ segments:
112
+ - 2
113
+ - 0
114
+ - 0
115
+ - beta
116
+ - 20
117
+ version: 2.0.0.beta.20
118
+ type: :development
119
+ version_requirements: *id006
120
+ - !ruby/object:Gem::Dependency
121
+ name: bson_ext
122
+ prerelease: false
123
+ requirement: &id007 !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 25
129
+ segments:
130
+ - 1
131
+ - 1
132
+ - 5
133
+ version: 1.1.5
134
+ type: :development
135
+ version_requirements: *id007
136
+ - !ruby/object:Gem::Dependency
137
+ name: rspec
138
+ prerelease: false
139
+ requirement: &id008 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 31
145
+ segments:
146
+ - 2
147
+ - 4
148
+ - 0
149
+ version: 2.4.0
150
+ type: :development
151
+ version_requirements: *id008
152
+ - !ruby/object:Gem::Dependency
153
+ name: sqlite3-ruby
154
+ prerelease: false
155
+ requirement: &id009 !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 31
161
+ segments:
162
+ - 1
163
+ - 3
164
+ - 2
165
+ version: 1.3.2
166
+ type: :development
167
+ version_requirements: *id009
168
+ - !ruby/object:Gem::Dependency
169
+ name: datamapper
170
+ prerelease: false
171
+ requirement: &id010 !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ hash: 15
177
+ segments:
178
+ - 1
179
+ - 0
180
+ version: "1.0"
181
+ type: :development
182
+ version_requirements: *id010
183
+ - !ruby/object:Gem::Dependency
184
+ name: dm-sqlite-adapter
185
+ prerelease: false
186
+ requirement: &id011 !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ hash: 15
192
+ segments:
193
+ - 1
194
+ - 0
195
+ version: "1.0"
196
+ type: :development
197
+ version_requirements: *id011
198
+ - !ruby/object:Gem::Dependency
199
+ name: dm-active_model
200
+ prerelease: false
201
+ requirement: &id012 !ruby/object:Gem::Requirement
202
+ none: false
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ hash: 15
207
+ segments:
208
+ - 1
209
+ - 0
210
+ version: "1.0"
211
+ type: :development
212
+ version_requirements: *id012
22
213
  description: Provides a single point of entry for using basic features of ruby ORMs
23
214
  email: ian.w.white@gmail.com
24
215
  executables: []
25
216
 
26
217
  extensions: []
27
218
 
28
- extra_rdoc_files:
29
- - LICENSE
30
- - README.rdoc
219
+ extra_rdoc_files: []
220
+
31
221
  files:
32
222
  - .gitignore
33
223
  - Gemfile
34
- - Gemfile.lock
224
+ - Gemfile.lock.development
35
225
  - History.txt
36
226
  - LICENSE
37
227
  - README.rdoc
@@ -47,6 +237,7 @@ files:
47
237
  - spec/orm_adapter/adapters/active_record_spec.rb
48
238
  - spec/orm_adapter/adapters/data_mapper_spec.rb
49
239
  - spec/orm_adapter/adapters/mongoid_spec.rb
240
+ - spec/orm_adapter/base_spec.rb
50
241
  - spec/orm_adapter/example_app_shared.rb
51
242
  - spec/orm_adapter_spec.rb
52
243
  - spec/spec_helper.rb
@@ -55,8 +246,8 @@ homepage: http://github.com/ianwhite/orm_adapter
55
246
  licenses: []
56
247
 
57
248
  post_install_message:
58
- rdoc_options:
59
- - --charset=UTF-8
249
+ rdoc_options: []
250
+
60
251
  require_paths:
61
252
  - lib
62
253
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -64,6 +255,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
255
  requirements:
65
256
  - - ">="
66
257
  - !ruby/object:Gem::Version
258
+ hash: 3
67
259
  segments:
68
260
  - 0
69
261
  version: "0"
@@ -72,20 +264,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
264
  requirements:
73
265
  - - ">="
74
266
  - !ruby/object:Gem::Version
267
+ hash: 23
75
268
  segments:
76
- - 0
77
- version: "0"
269
+ - 1
270
+ - 3
271
+ - 6
272
+ version: 1.3.6
78
273
  requirements: []
79
274
 
80
- rubyforge_project:
275
+ rubyforge_project: orm_adapter
81
276
  rubygems_version: 1.3.7
82
277
  signing_key:
83
278
  specification_version: 3
84
- summary: Provides a single point of entry for using basic features of ruby ORMs
279
+ summary: orm_adapter provides a single point of entry for using basic features of popular ruby ORMs. Its target audience is gem authors who want to support many ruby ORMs.
85
280
  test_files:
86
281
  - spec/orm_adapter/adapters/active_record_spec.rb
87
282
  - spec/orm_adapter/adapters/data_mapper_spec.rb
88
283
  - spec/orm_adapter/adapters/mongoid_spec.rb
284
+ - spec/orm_adapter/base_spec.rb
89
285
  - spec/orm_adapter/example_app_shared.rb
90
286
  - spec/orm_adapter_spec.rb
91
287
  - spec/spec_helper.rb