dm-persevere-adapter 0.51.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/persevere_adapter.rb +19 -7
- data/spec/persevere_adapter_spec.rb +12 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.52.0
|
data/lib/persevere_adapter.rb
CHANGED
@@ -3,7 +3,7 @@ require 'dm-core'
|
|
3
3
|
require 'dm-aggregates'
|
4
4
|
require 'dm-types'
|
5
5
|
require 'extlib'
|
6
|
-
require 'json'
|
6
|
+
# require 'json'
|
7
7
|
require 'bigdecimal'
|
8
8
|
|
9
9
|
require 'model_json_support'
|
@@ -708,6 +708,15 @@ module DataMapper
|
|
708
708
|
end
|
709
709
|
end
|
710
710
|
|
711
|
+
def munge_condition(condition)
|
712
|
+
cond = condition.loaded_value
|
713
|
+
|
714
|
+
cond = "\"#{cond}\"" if cond.is_a?(String)
|
715
|
+
cond = "date(%10.f)" % (Time.parse(cond.to_s).to_f * 1000) if cond.is_a?(DateTime)
|
716
|
+
cond = 'undefined' if cond.nil?
|
717
|
+
return cond
|
718
|
+
end
|
719
|
+
|
711
720
|
def process_condition(condition)
|
712
721
|
case condition
|
713
722
|
# Persevere 1.0 regular expressions are disable for security so we pass them back for DataMapper query filtering
|
@@ -724,12 +733,15 @@ module DataMapper
|
|
724
733
|
inside.empty? ? [] : "!(%s)" % inside
|
725
734
|
when DataMapper::Query::Conditions::InclusionComparison then process_in(condition.subject.name, condition.value)
|
726
735
|
when DataMapper::Query::Conditions::EqualToComparison then
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
736
|
+
"#{condition.subject.field}=#{munge_condition(condition)}"
|
737
|
+
when DataMapper::Query::Conditions::GreaterThanComparison then
|
738
|
+
"#{condition.subject.field}>#{munge_condition(condition)}"
|
739
|
+
when DataMapper::Query::Conditions::LessThanComparison then
|
740
|
+
"#{condition.subject.field}<#{munge_condition(condition)}"
|
741
|
+
when DataMapper::Query::Conditions::GreaterThanOrEqualToComparison then
|
742
|
+
"#{condition.subject.field}>=#{munge_condition(condition)}"
|
743
|
+
when DataMapper::Query::Conditions::LessThanOrEqualToComparison then
|
744
|
+
"#{condition.subject.field}<=#{munge_condition(condition)}"
|
733
745
|
when DataMapper::Query::Conditions::NullOperation then []
|
734
746
|
when Array then
|
735
747
|
old_statement, bind_values = condition
|
@@ -193,7 +193,18 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
193
193
|
|
194
194
|
it_should_behave_like 'An Aggregatable Class'
|
195
195
|
|
196
|
-
it "should be able to get a count of objects within a range of dates"
|
196
|
+
it "should be able to get a count of objects within a range of dates" do
|
197
|
+
Bozon.auto_migrate!
|
198
|
+
orig_date = DateTime.now - 7
|
199
|
+
Bozon.create(:author => 'Robbie', :created_at => orig_date, :title => '1 week ago')
|
200
|
+
Bozon.create(:author => 'Ivan', :created_at => DateTime.now, :title => 'About Now')
|
201
|
+
Bozon.create(:author => 'Sean', :created_at => DateTime.now + 7, :title => 'Sometime later')
|
202
|
+
|
203
|
+
Bozon.count.should eql(3)
|
204
|
+
Bozon.count(:created_at => orig_date).should eql(1)
|
205
|
+
Bozon.count(:created_at.gt => orig_date).should eql(2)
|
206
|
+
Bozon.auto_migrate_down!
|
207
|
+
end
|
197
208
|
|
198
209
|
it "should count with like conditions" do
|
199
210
|
Country.count(:name.like => '%n%').should == 4
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 52
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.52.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ivan R. Judson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-04-
|
18
|
+
date: 2010-04-26 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|