mongo_mapper-unstable 2010.2.9 → 2010.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -267,6 +267,14 @@ class SupportTest < Test::Unit::TestCase
267
267
  end
268
268
  end
269
269
 
270
+ context "Symbol" do
271
+ %w(gt lt gte lte ne in nin mod all size where exists asc desc).each do |operator|
272
+ should "have $#{operator} operator" do
273
+ :foo.respond_to?(operator)
274
+ end
275
+ end
276
+ end
277
+
270
278
  context "Time#to_mongo without Time.zone" do
271
279
  should "be time to milliseconds if string" do
272
280
  Time.to_mongo('2000-01-01 01:01:01.123456').should == Time.local(2000, 1, 1, 1, 1, 1, 123000).utc
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper-unstable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2010.2.9
4
+ version: 2010.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-09 00:00:00 -05:00
12
+ date: 2010-02-10 00:00:00 -05:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -101,7 +101,6 @@ files:
101
101
  - lib/mongo_mapper.rb
102
102
  - lib/mongo_mapper/document.rb
103
103
  - lib/mongo_mapper/embedded_document.rb
104
- - lib/mongo_mapper/finder_options.rb
105
104
  - lib/mongo_mapper/plugins.rb
106
105
  - lib/mongo_mapper/plugins/associations.rb
107
106
  - lib/mongo_mapper/plugins/associations/base.rb
@@ -127,10 +126,12 @@ files:
127
126
  - lib/mongo_mapper/plugins/keys.rb
128
127
  - lib/mongo_mapper/plugins/logger.rb
129
128
  - lib/mongo_mapper/plugins/pagination.rb
129
+ - lib/mongo_mapper/plugins/pagination/proxy.rb
130
130
  - lib/mongo_mapper/plugins/protected.rb
131
131
  - lib/mongo_mapper/plugins/rails.rb
132
132
  - lib/mongo_mapper/plugins/serialization.rb
133
133
  - lib/mongo_mapper/plugins/validations.rb
134
+ - lib/mongo_mapper/query.rb
134
135
  - lib/mongo_mapper/support.rb
135
136
  - lib/mongo_mapper/support/descendant_appends.rb
136
137
  - lib/mongo_mapper/support/find.rb
@@ -171,11 +172,11 @@ files:
171
172
  - test/unit/test_document.rb
172
173
  - test/unit/test_dynamic_finder.rb
173
174
  - test/unit/test_embedded_document.rb
174
- - test/unit/test_finder_options.rb
175
175
  - test/unit/test_keys.rb
176
176
  - test/unit/test_mongo_mapper.rb
177
177
  - test/unit/test_pagination.rb
178
178
  - test/unit/test_plugins.rb
179
+ - test/unit/test_query.rb
179
180
  - test/unit/test_rails.rb
180
181
  - test/unit/test_rails_compatibility.rb
181
182
  - test/unit/test_serialization.rb
@@ -215,13 +216,13 @@ test_files:
215
216
  - test/unit/test_dynamic_finder.rb
216
217
  - test/unit/serializers/test_json_serializer.rb
217
218
  - test/unit/test_support.rb
218
- - test/unit/test_finder_options.rb
219
219
  - test/unit/test_keys.rb
220
220
  - test/unit/associations/test_proxy.rb
221
221
  - test/unit/associations/test_base.rb
222
222
  - test/unit/test_time_zones.rb
223
223
  - test/unit/test_serialization.rb
224
224
  - test/unit/test_rails.rb
225
+ - test/unit/test_query.rb
225
226
  - test/unit/test_rails_compatibility.rb
226
227
  - test/unit/test_validations.rb
227
228
  - test/unit/test_mongo_mapper.rb
@@ -1,127 +0,0 @@
1
- module MongoMapper
2
- # = Important Note
3
- # This class is private to MongoMapper and should not be considered part of
4
- # MongoMapper's public API.
5
- #
6
- class FinderOptions
7
- OptionKeys = [:fields, :select, :skip, :offset, :limit, :sort, :order]
8
-
9
- def self.normalized_field(field)
10
- field.to_s == 'id' ? :_id : field
11
- end
12
-
13
- def self.normalized_order_direction(direction)
14
- direction ||= 'ASC'
15
- direction.upcase == 'ASC' ? 1 : -1
16
- end
17
-
18
- def initialize(model, options)
19
- raise ArgumentError, "Options must be a hash" unless options.is_a?(Hash)
20
-
21
- @model = model
22
- @options = {}
23
- @conditions = {}
24
-
25
- options.each_pair do |key, value|
26
- key = key.respond_to?(:to_sym) ? key.to_sym : key
27
- if OptionKeys.include?(key)
28
- @options[key] = value
29
- elsif key == :conditions
30
- @conditions.merge!(value)
31
- else
32
- @conditions[key] = value
33
- end
34
- end
35
-
36
- add_sci_scope
37
- end
38
-
39
- def criteria
40
- to_mongo_criteria(@conditions)
41
- end
42
-
43
- def options
44
- fields = @options[:fields] || @options[:select]
45
- skip = @options[:skip] || @options[:offset] || 0
46
- limit = @options[:limit] || 0
47
- sort = @options[:sort] || convert_order_to_sort(@options[:order])
48
-
49
- {:fields => to_mongo_fields(fields), :skip => skip.to_i, :limit => limit.to_i, :sort => sort}
50
- end
51
-
52
- def to_a
53
- [criteria, options]
54
- end
55
-
56
- private
57
- def to_mongo_criteria(conditions, parent_key=nil)
58
- criteria = {}
59
-
60
- conditions.each_pair do |field, value|
61
- field = self.class.normalized_field(field)
62
-
63
- if @model.object_id_key?(field) && value.is_a?(String)
64
- value = Mongo::ObjectID.from_string(value)
65
- end
66
-
67
- if field.is_a?(SymbolOperator)
68
- criteria.update(field.to_mm_criteria(value))
69
- next
70
- end
71
-
72
- case value
73
- when Array
74
- criteria[field] = operator?(field) ? value : {'$in' => value}
75
- when Hash
76
- criteria[field] = to_mongo_criteria(value, field)
77
- when Time
78
- criteria[field] = value.utc
79
- else
80
- criteria[field] = value
81
- end
82
- end
83
-
84
- criteria
85
- end
86
-
87
- def operator?(field)
88
- field.to_s =~ /^\$/
89
- end
90
-
91
- # adds _type single collection inheritance scope for models that need it
92
- def add_sci_scope
93
- if @model.single_collection_inherited?
94
- @conditions[:_type] = @model.to_s
95
- end
96
- end
97
-
98
- def to_mongo_fields(fields)
99
- return if fields.blank?
100
-
101
- if fields.respond_to?(:flatten, :compact)
102
- fields.flatten.compact
103
- else
104
- fields.split(',').map { |field| field.strip }
105
- end
106
- end
107
-
108
- def convert_order_to_sort(sort)
109
- return if sort.blank?
110
-
111
- if sort.respond_to?(:all?) && sort.all? { |s| s.respond_to?(:to_mm_order) }
112
- sort.map { |s| s.to_mm_order }
113
- elsif sort.respond_to?(:to_mm_order)
114
- [sort.to_mm_order]
115
- else
116
- pieces = sort.split(',')
117
- pieces.map { |s| to_mongo_sort_piece(s) }
118
- end
119
- end
120
-
121
- def to_mongo_sort_piece(str)
122
- field, direction = str.strip.split(' ')
123
- direction = FinderOptions.normalized_order_direction(direction)
124
- [field, direction]
125
- end
126
- end
127
- end