dm-persevere-adapter 0.40.0 → 0.41.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/model_json_support.rb +2 -2
- data/lib/persevere_adapter.rb +23 -4
- data/spec/persevere_adapter_spec.rb +3 -6
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.41.0
|
data/lib/model_json_support.rb
CHANGED
@@ -23,8 +23,8 @@ module DataMapper
|
|
23
23
|
tm = repository(repo).adapter.type_map
|
24
24
|
json_hash = { "type" => tm[type][:primitive] }
|
25
25
|
json_hash.merge!( tm[type].reject{ |key,value| key == :primitive } )
|
26
|
-
json_hash.merge!({ "optional" => true }) unless required?
|
27
|
-
json_hash.merge!({ "unique" => true}) if unique?
|
26
|
+
json_hash.merge!({ "optional" => true }) unless required?
|
27
|
+
json_hash.merge!({ "unique" => true}) if unique?
|
28
28
|
json_hash.merge!({"position" => @position }) unless @position.nil?
|
29
29
|
# MIN
|
30
30
|
# MAX
|
data/lib/persevere_adapter.rb
CHANGED
@@ -360,7 +360,7 @@ module DataMapper
|
|
360
360
|
|
361
361
|
tblname = query.model.storage_name
|
362
362
|
path = "/#{tblname}/#{json_query}"
|
363
|
-
puts path
|
363
|
+
# puts path
|
364
364
|
response = @persevere.retrieve(path, headers)
|
365
365
|
|
366
366
|
if response.code.match(/20?/)
|
@@ -369,7 +369,11 @@ module DataMapper
|
|
369
369
|
# Typecast attributes, DM expects them properly cast
|
370
370
|
query.model.properties.each do |prop|
|
371
371
|
value = rsrc_hash[prop.field.to_s]
|
372
|
-
|
372
|
+
if prop.field == 'id'
|
373
|
+
rsrc_hash[prop.field.to_s] = value.to_s.match(/\d+$/)[0].to_i
|
374
|
+
else
|
375
|
+
rsrc_hash[prop.field.to_s] = prop.typecast(value) unless value.nil?
|
376
|
+
end
|
373
377
|
# Shift date/time objects to the correct timezone because persevere is UTC
|
374
378
|
case prop
|
375
379
|
when DateTime then rsrc_hash[prop.field.to_s] = value.new_offset(Rational(Time.now.getlocal.gmt_offset/3600, 24))
|
@@ -380,7 +384,16 @@ module DataMapper
|
|
380
384
|
resources = query.model.load(results, query)
|
381
385
|
end
|
382
386
|
# We could almost elimate this if regexp was working in persevere.
|
383
|
-
|
387
|
+
|
388
|
+
# This won't work if the RegExp is nested more then 1 layer deep.
|
389
|
+
if query.conditions.class == DataMapper::Query::Conditions::AndOperation
|
390
|
+
regexp_conds = query.conditions.operands.select{ |obj| obj.is_a?(DataMapper::Query::Conditions::RegexpComparison) ||
|
391
|
+
(obj.is_a?(DataMapper::Query::Conditions::NotOperation) && obj.operand.is_a?(DataMapper::Query::Conditions::RegexpComparison))}
|
392
|
+
regexp_conds.each{|cond| resources = resources.select{|resource| cond.matches?(resource)} }
|
393
|
+
|
394
|
+
end
|
395
|
+
# query.match_records(resources)
|
396
|
+
resources
|
384
397
|
end
|
385
398
|
|
386
399
|
alias :read :read_many
|
@@ -638,9 +651,10 @@ module DataMapper
|
|
638
651
|
when DataMapper::Query::Conditions::InclusionComparison then process_in(condition.subject.name, condition.value)
|
639
652
|
when DataMapper::Query::Conditions::EqualToComparison then
|
640
653
|
cond = condition.loaded_value
|
641
|
-
|
654
|
+
|
642
655
|
cond = "\"#{cond}\"" if cond.is_a?(String)
|
643
656
|
cond = "date(%10.f)" % (Time.parse(cond.to_s).to_f * 1000) if cond.is_a?(DateTime)
|
657
|
+
cond = 'undefined' if cond.nil?
|
644
658
|
"#{condition.subject.name.to_s}=#{cond}"
|
645
659
|
when DataMapper::Query::Conditions::NullOperation then []
|
646
660
|
when Array then
|
@@ -656,6 +670,7 @@ module DataMapper
|
|
656
670
|
query_terms = Array.new
|
657
671
|
order_operations = Array.new
|
658
672
|
field_ops = Array.new
|
673
|
+
fields = Array.new
|
659
674
|
headers = Hash.new
|
660
675
|
|
661
676
|
query_terms << process_condition(query.conditions)
|
@@ -690,6 +705,8 @@ module DataMapper
|
|
690
705
|
when :avg
|
691
706
|
"[=#{field.target.name}]"
|
692
707
|
end
|
708
|
+
else
|
709
|
+
fields << "#{field.name}:#{field.name}"
|
693
710
|
end
|
694
711
|
end
|
695
712
|
|
@@ -706,6 +723,8 @@ module DataMapper
|
|
706
723
|
|
707
724
|
json_query += order_operations.join("")
|
708
725
|
|
726
|
+
json_query += "[={" + fields.join(',') + "}]" unless fields.empty?
|
727
|
+
|
709
728
|
offset = query.offset.to_i
|
710
729
|
limit = query.limit.nil? ? nil : query.limit.to_i + offset - 1
|
711
730
|
|
@@ -17,8 +17,7 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
17
17
|
class ::Bozon
|
18
18
|
include DataMapper::Resource
|
19
19
|
|
20
|
-
|
21
|
-
property :id, String, :serial => true
|
20
|
+
property :id, Serial
|
22
21
|
property :author, String
|
23
22
|
property :created_at, DateTime
|
24
23
|
property :title, String
|
@@ -26,9 +25,7 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
26
25
|
|
27
26
|
class ::Dataino
|
28
27
|
include DataMapper::Resource
|
29
|
-
|
30
|
-
# Persevere only does id's as strings.
|
31
|
-
property :id, String, :serial => true
|
28
|
+
property :id, Serial
|
32
29
|
property :author, String
|
33
30
|
property :created_at, DateTime
|
34
31
|
property :title, String
|
@@ -192,7 +189,7 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
192
189
|
it "should return data from an offset" do
|
193
190
|
result = Bozon.all(:limit => 5, :offset => 10)
|
194
191
|
result.length.should == 5
|
195
|
-
result.map { |item| item.id }.should == [
|
192
|
+
result.map { |item| item.id }.should == [11, 12, 13, 14, 15]
|
196
193
|
end
|
197
194
|
|
198
195
|
after(:all) do
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 41
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.41.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-03-
|
18
|
+
date: 2010-03-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|