cdq 0.1.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/LICENSE +21 -0
- data/README.md +206 -58
- data/lib/cdq/cli.rb +1 -13
- data/lib/cdq/version.rb +1 -1
- data/motion/cdq.rb +38 -3
- data/motion/cdq/context.rb +5 -0
- data/motion/cdq/partial_predicate.rb +64 -21
- data/motion/cdq/query.rb +69 -15
- data/motion/cdq/targeted_query.rb +0 -2
- data/templates/model/spec/models/name.rb +1 -1
- metadata +12 -53
- data/.gitignore +0 -12
- data/.travis.yml +0 -2
- data/Gemfile +0 -7
- data/Gemfile.lock +0 -32
- data/Rakefile +0 -28
- data/app/app_delegate.rb +0 -13
- data/app/test_models.rb +0 -15
- data/cdq.gemspec +0 -20
- data/resources/CDQ.xcdatamodeld/.xccurrentversion +0 -8
- data/resources/CDQ.xcdatamodeld/0.0.1.xcdatamodel/contents +0 -34
- data/resources/Default-568h@2x.png +0 -0
- data/resources/KEEPME +0 -0
- data/schemas/001_baseline.rb +0 -44
- data/spec/cdq/collection_proxy_spec.rb +0 -51
- data/spec/cdq/config_spec.rb +0 -74
- data/spec/cdq/context_spec.rb +0 -92
- data/spec/cdq/managed_object_spec.rb +0 -81
- data/spec/cdq/model_spec.rb +0 -14
- data/spec/cdq/module_spec.rb +0 -44
- data/spec/cdq/object_proxy_spec.rb +0 -37
- data/spec/cdq/object_spec.rb +0 -58
- data/spec/cdq/partial_predicate_spec.rb +0 -52
- data/spec/cdq/query_spec.rb +0 -127
- data/spec/cdq/relationship_query_spec.rb +0 -75
- data/spec/cdq/store_spec.rb +0 -39
- data/spec/cdq/targeted_query_spec.rb +0 -120
- data/spec/helpers/thread_helper.rb +0 -16
- data/spec/integration_spec.rb +0 -38
@@ -1,120 +0,0 @@
|
|
1
|
-
|
2
|
-
module CDQ
|
3
|
-
describe "CDQ Targeted Query" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
CDQ.cdq.setup
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
CDQ.cdq.reset!
|
11
|
-
end
|
12
|
-
|
13
|
-
it "reflects a base state" do
|
14
|
-
tq = CDQTargetedQuery.new(Author.entity_description, Author)
|
15
|
-
tq.count.should == 0
|
16
|
-
tq.array.should == []
|
17
|
-
end
|
18
|
-
|
19
|
-
it "can count objects" do
|
20
|
-
tq = CDQTargetedQuery.new(Author.entity_description, Author)
|
21
|
-
Author.create(name: "eecummings")
|
22
|
-
tq.count.should == 1
|
23
|
-
Author.create(name: "T. S. Eliot")
|
24
|
-
tq.count.should == 2
|
25
|
-
end
|
26
|
-
|
27
|
-
it "can fetch objects" do
|
28
|
-
tq = CDQTargetedQuery.new(Author.entity_description, Author)
|
29
|
-
eecummings = Author.create(name: "eecummings")
|
30
|
-
tseliot = Author.create(name: "T. S. Eliot")
|
31
|
-
tq.array.sort_by(&:name).should == [tseliot, eecummings]
|
32
|
-
end
|
33
|
-
|
34
|
-
it "can create objects" do
|
35
|
-
tq = CDQTargetedQuery.new(Author.entity_description, Author)
|
36
|
-
maya = tq.create(name: "maya angelou")
|
37
|
-
tq.where(:name).eq("maya angelou").first.should == maya
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "CDQ Targeted Query with data" do
|
43
|
-
|
44
|
-
before do
|
45
|
-
CDQ.cdq.setup
|
46
|
-
|
47
|
-
class << self
|
48
|
-
include CDQ
|
49
|
-
end
|
50
|
-
|
51
|
-
@tq = cdq(Author)
|
52
|
-
@eecummings = Author.create(name: "eecummings")
|
53
|
-
@tseliot = Author.create(name: "T. S. Eliot")
|
54
|
-
@dante = Author.create(name: "dante")
|
55
|
-
cdq.save
|
56
|
-
end
|
57
|
-
|
58
|
-
after do
|
59
|
-
CDQ.cdq.reset!
|
60
|
-
end
|
61
|
-
|
62
|
-
it "performs a sorted fetch" do
|
63
|
-
@tq.sort_by(:name).array.should == [@tseliot, @dante, @eecummings]
|
64
|
-
end
|
65
|
-
|
66
|
-
it "performs a limited fetch" do
|
67
|
-
@tq.sort_by(:name).limit(1).array.should == [@tseliot]
|
68
|
-
end
|
69
|
-
|
70
|
-
it "performs an offset fetch" do
|
71
|
-
@tq.sort_by(:name).offset(1).array.should == [@dante, @eecummings]
|
72
|
-
@tq.sort_by(:name).offset(1).limit(1).array.should == [@dante]
|
73
|
-
end
|
74
|
-
|
75
|
-
it "performs a restricted search" do
|
76
|
-
@tq.where(:name).eq("dante").array.should == [@dante]
|
77
|
-
end
|
78
|
-
|
79
|
-
it "gets the first entry" do
|
80
|
-
@tq.sort_by(:name).first.should == @tseliot
|
81
|
-
end
|
82
|
-
|
83
|
-
it "gets entries by index" do
|
84
|
-
@tq.sort_by(:name)[0].should == @tseliot
|
85
|
-
@tq.sort_by(:name)[1].should == @dante
|
86
|
-
@tq.sort_by(:name)[2].should == @eecummings
|
87
|
-
end
|
88
|
-
|
89
|
-
it "can iterate over entries" do
|
90
|
-
entries = [@tseliot, @dante, @eecummings]
|
91
|
-
|
92
|
-
@tq.sort_by(:name).each do |e|
|
93
|
-
e.should == entries.shift
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
it "can map over entries" do
|
98
|
-
entries = [@tseliot, @dante, @eecummings]
|
99
|
-
|
100
|
-
@tq.sort_by(:name).map { |e| e }.should == entries
|
101
|
-
end
|
102
|
-
|
103
|
-
it "can create a named scope" do
|
104
|
-
@tq.scope :two_sorted_by_name, @tq.sort_by(:name).limit(2)
|
105
|
-
@tq.two_sorted_by_name.array.should == [@tseliot, @dante]
|
106
|
-
end
|
107
|
-
|
108
|
-
it "can create a dynamic named scope" do
|
109
|
-
tq = cdq(Article)
|
110
|
-
a = tq.create(publishedAt: Time.local(2001))
|
111
|
-
b = tq.create(publishedAt: Time.local(2002))
|
112
|
-
c = tq.create(publishedAt: Time.local(2003))
|
113
|
-
d = tq.create(publishedAt: Time.local(2004))
|
114
|
-
|
115
|
-
tq.scope :date_span { |start_date, end_date| cdq(:publishedAt).lt(end_date).and.ge(start_date) }
|
116
|
-
tq.date_span(Time.local(2002), Time.local(2004)).sort_by(:publishedAt).array.should == [b, c]
|
117
|
-
Article.published_since(Time.local(2003)).sort_by(:publishedAt).array.should == [c, d]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Bacon
|
2
|
-
class Context
|
3
|
-
# Executes a given block on an async concurrent GCD queue (which is a
|
4
|
-
# different thread) and returns the return value of the block, which is
|
5
|
-
# expected to be either true or false.
|
6
|
-
def on_thread(&block)
|
7
|
-
@result = false
|
8
|
-
group = Dispatch::Group.new
|
9
|
-
Dispatch::Queue.concurrent.async(group) do
|
10
|
-
@result = block.call
|
11
|
-
end
|
12
|
-
group.wait
|
13
|
-
@result
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/spec/integration_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "Integration Tests" do
|
3
|
-
|
4
|
-
before do
|
5
|
-
|
6
|
-
class << self
|
7
|
-
include CDQ
|
8
|
-
end
|
9
|
-
|
10
|
-
cdq.setup
|
11
|
-
|
12
|
-
@author = Author.create(name: "Albert Einstein")
|
13
|
-
|
14
|
-
@fundamentals = @author.articles.create(body: "...", published: true, publishedAt: Time.local(1940),
|
15
|
-
title: "Considerations concering the fundamentals of theoretical physics")
|
16
|
-
|
17
|
-
@gravitation = @author.articles.create(body: "...", published: true, publishedAt: Time.local(1937),
|
18
|
-
title: "On gravitational waves")
|
19
|
-
|
20
|
-
@fcite = @fundamentals.citations.create(journal: "Science", timestamp: Time.local(1940))
|
21
|
-
@gcite = @gravitation.citations.create(journal: "Nature", timestamp: Time.local(1941))
|
22
|
-
|
23
|
-
cdq.save(always_wait: true)
|
24
|
-
end
|
25
|
-
|
26
|
-
after do
|
27
|
-
cdq.reset!
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should be able to combine simple queries" do
|
31
|
-
@author.articles.count.should == 2
|
32
|
-
@author.articles.first.citations.count.should == 1
|
33
|
-
@author.articles.where(:title).matches('.*fundamentals.*').first.citations.array.should == [@fcite]
|
34
|
-
|
35
|
-
@gcite.article.author.should == @author
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|