cdq 0.1.2 → 0.1.5
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.
- 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
data/app/app_delegate.rb
DELETED
data/app/test_models.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
class Author < CDQManagedObject
|
2
|
-
end
|
3
|
-
|
4
|
-
class Article < CDQManagedObject
|
5
|
-
scope :all_published, where(:published).eq(true)
|
6
|
-
scope :with_title, where(:title).ne(nil).sort_by(:title, :descending)
|
7
|
-
scope :published_since { |date| where(:publishedAt).ge(date) }
|
8
|
-
end
|
9
|
-
|
10
|
-
class Citation < CDQManagedObject
|
11
|
-
end
|
12
|
-
|
13
|
-
class Writer < CDQManagedObject
|
14
|
-
end
|
15
|
-
|
data/cdq.gemspec
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/cdq/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["infinitered", "kemiller"]
|
6
|
-
gem.email = ["ken@infinitered.com"]
|
7
|
-
gem.description = "Core Data Query for RubyMotion"
|
8
|
-
gem.summary = "Core Data Query for RubyMotion"
|
9
|
-
gem.homepage = "http://github.com/infinitered/cdq"
|
10
|
-
|
11
|
-
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
-
gem.name = "cdq"
|
14
|
-
gem.require_paths = ["lib"]
|
15
|
-
gem.add_runtime_dependency 'ruby-xcdm', '~> 0.0', '>= 0.0.5'
|
16
|
-
gem.add_runtime_dependency 'motion-yaml'
|
17
|
-
gem.executables << 'cdq'
|
18
|
-
|
19
|
-
gem.version = CDQ::VERSION
|
20
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
-
<plist version="1.0">
|
4
|
-
<dict>
|
5
|
-
<key>_XCCurrentVersionName</key>
|
6
|
-
<string>0.0.1.xcdatamodel</string>
|
7
|
-
</dict>
|
8
|
-
</plist>
|
@@ -1,34 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
-
<model name="" userDefinedModelVersionIdentifier="0.0.1" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="2061" systemVersion="12D78" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
|
3
|
-
<entity name="Article" syncable="YES" representedClassName="Article">
|
4
|
-
<attribute optional="NO" syncable="YES" attributeType="String" name="body"/>
|
5
|
-
<attribute optional="YES" syncable="YES" attributeType="Integer 32" name="length" defaultValueString="0"/>
|
6
|
-
<attribute optional="YES" syncable="YES" attributeType="Boolean" name="published" defaultValueString="NO"/>
|
7
|
-
<attribute optional="YES" syncable="YES" attributeType="Date" name="publishedAt" defaultValueString="NO"/>
|
8
|
-
<attribute optional="NO" syncable="YES" attributeType="String" name="title"/>
|
9
|
-
<relationship optional="YES" deletionRule="Nullify" syncable="YES" name="author" inverseEntity="Author" destinationEntity="Author" inverseName="articles" maxCount="1"/>
|
10
|
-
<relationship optional="YES" deletionRule="Nullify" syncable="YES" name="citations" inverseEntity="Citation" destinationEntity="Citation" inverseName="article" toMany="YES"/>
|
11
|
-
</entity>
|
12
|
-
<entity name="Author" syncable="YES" representedClassName="Author">
|
13
|
-
<attribute optional="NO" syncable="YES" attributeType="String" name="name"/>
|
14
|
-
<attribute optional="YES" syncable="YES" attributeType="Float" name="fee" defaultValueString="0.0"/>
|
15
|
-
<relationship optional="YES" deletionRule="Nullify" syncable="YES" name="articles" inverseEntity="Article" destinationEntity="Article" inverseName="author" toMany="YES"/>
|
16
|
-
</entity>
|
17
|
-
<entity name="Writer" syncable="YES" representedClassName="Writer">
|
18
|
-
<attribute optional="NO" syncable="YES" attributeType="String" name="name"/>
|
19
|
-
<attribute optional="YES" syncable="YES" attributeType="Float" name="fee" defaultValueString="0.0"/>
|
20
|
-
<relationship optional="YES" deletionRule="Nullify" syncable="YES" name="spouses" inverseEntity="Spouse" destinationEntity="Spouse" inverseName="writers" toMany="YES" ordered="YES"/>
|
21
|
-
</entity>
|
22
|
-
<entity name="Spouse" syncable="YES" representedClassName="CDQManagedObject">
|
23
|
-
<attribute optional="YES" syncable="YES" attributeType="String" name="name"/>
|
24
|
-
<relationship optional="YES" deletionRule="Nullify" syncable="YES" name="writers" inverseEntity="Writer" destinationEntity="Writer" inverseName="spouses" toMany="YES"/>
|
25
|
-
</entity>
|
26
|
-
<entity name="Publisher" syncable="YES" representedClassName="CDQManagedObject">
|
27
|
-
<attribute optional="NO" syncable="YES" attributeType="String" name="name"/>
|
28
|
-
</entity>
|
29
|
-
<entity name="Citation" syncable="YES" representedClassName="Citation">
|
30
|
-
<attribute optional="YES" syncable="YES" attributeType="String" name="journal"/>
|
31
|
-
<attribute optional="YES" syncable="YES" attributeType="Date" name="timestamp"/>
|
32
|
-
<relationship optional="YES" deletionRule="Nullify" syncable="YES" name="article" inverseEntity="Article" destinationEntity="Article" inverseName="citations" maxCount="1"/>
|
33
|
-
</entity>
|
34
|
-
</model>
|
Binary file
|
data/resources/KEEPME
DELETED
File without changes
|
data/schemas/001_baseline.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
|
2
|
-
schema "0.0.1" do
|
3
|
-
|
4
|
-
entity "Article" do
|
5
|
-
|
6
|
-
string :body, optional: false
|
7
|
-
integer32 :length
|
8
|
-
boolean :published, default: false
|
9
|
-
datetime :publishedAt, default: false
|
10
|
-
string :title, optional: false
|
11
|
-
|
12
|
-
belongs_to :author
|
13
|
-
has_many :citations
|
14
|
-
end
|
15
|
-
|
16
|
-
entity "Author" do
|
17
|
-
string :name, optional: false
|
18
|
-
float :fee
|
19
|
-
has_many :articles
|
20
|
-
end
|
21
|
-
|
22
|
-
entity "Writer" do
|
23
|
-
string :name, optional: false
|
24
|
-
float :fee
|
25
|
-
|
26
|
-
has_many :spouses, inverse: "Spouse.writers", ordered: true
|
27
|
-
end
|
28
|
-
|
29
|
-
entity "Spouse", class_name: "CDQManagedObject" do
|
30
|
-
string :name, optional: true
|
31
|
-
has_many :writers, inverse: "Writer.spouses"
|
32
|
-
end
|
33
|
-
|
34
|
-
entity "Publisher", class_name: "CDQManagedObject" do
|
35
|
-
string :name, optional: false
|
36
|
-
end
|
37
|
-
|
38
|
-
entity "Citation" do
|
39
|
-
string :journal
|
40
|
-
datetime :timestamp
|
41
|
-
belongs_to :article
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
|
2
|
-
module CDQ
|
3
|
-
describe "CDQ Collection Proxy" do
|
4
|
-
before do
|
5
|
-
class << self
|
6
|
-
include CDQ
|
7
|
-
end
|
8
|
-
|
9
|
-
cdq.setup
|
10
|
-
|
11
|
-
@author = Author.create(name: "Stephen King")
|
12
|
-
@articles = [
|
13
|
-
Article.create(title: "The Gunslinger", author: @author),
|
14
|
-
Article.create(title: "The Drawing of the Three", author: @author),
|
15
|
-
Article.create(title: "The Waste Lands", author: @author),
|
16
|
-
Article.create(title: "Wizard and Glass", author: @author),
|
17
|
-
Article.create(title: "The Wolves of the Calla", author: @author),
|
18
|
-
Article.create(title: "Song of Susannah", author: @author),
|
19
|
-
Article.create(title: "The Dark Tower", author: @author)
|
20
|
-
]
|
21
|
-
|
22
|
-
@cp = CDQCollectionProxy.new(@articles, @articles.first.entity)
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
after do
|
27
|
-
cdq.reset!
|
28
|
-
end
|
29
|
-
|
30
|
-
it "wraps an array of objects" do
|
31
|
-
@cp.get.should == @articles
|
32
|
-
end
|
33
|
-
|
34
|
-
it "can use a where query" do
|
35
|
-
q = @cp.where(:title).contains(" of ").sort_by(:title)
|
36
|
-
q.count.should == 3
|
37
|
-
q.array.should == [1,4,5].map { |i| @articles[i] }.sort_by(&:title)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "behaves properly when given an empty set" do
|
41
|
-
cp = CDQCollectionProxy.new([], @articles.first.entity)
|
42
|
-
cp.get.should == []
|
43
|
-
cp.count.should == 0
|
44
|
-
q = cp.or(:title).contains(" of ").sort_by(:title)
|
45
|
-
q.count.should == 3
|
46
|
-
q.array.should == [1,4,5].map { |i| @articles[i] }.sort_by(&:title)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
data/spec/cdq/config_spec.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module CDQ
|
4
|
-
|
5
|
-
describe "CDQ Config" do
|
6
|
-
|
7
|
-
before do
|
8
|
-
@bundle_name = NSBundle.mainBundle.objectForInfoDictionaryKey("CFBundleDisplayName")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "sets default values when no config file present" do
|
12
|
-
config = CDQConfig.new(nil)
|
13
|
-
config.name.should == @bundle_name
|
14
|
-
config.database_name.should == config.name
|
15
|
-
config.model_name.should == config.name
|
16
|
-
end
|
17
|
-
|
18
|
-
it "can initialize values from a hash" do
|
19
|
-
config = CDQConfig.new(name: "foo")
|
20
|
-
config.name.should == "foo"
|
21
|
-
config.database_name.should == "foo"
|
22
|
-
config.model_name.should == "foo"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "can override the default name" do
|
26
|
-
cf_file = File.join(NSBundle.mainBundle.bundlePath, "cdq.yml")
|
27
|
-
yaml_to_file(cf_file, name: "foo")
|
28
|
-
config = CDQConfig.new(cf_file)
|
29
|
-
config.name.should == "foo"
|
30
|
-
config.database_name.should == "foo"
|
31
|
-
config.model_name.should == "foo"
|
32
|
-
File.unlink(cf_file)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "can override database_name specifically" do
|
36
|
-
cf_file = File.join(NSBundle.mainBundle.bundlePath, "cdq.yml")
|
37
|
-
yaml_to_file(cf_file, database_name: "foo")
|
38
|
-
config = CDQConfig.new(cf_file)
|
39
|
-
config.name.should == @bundle_name
|
40
|
-
config.database_name.should == "foo"
|
41
|
-
config.model_name.should == config.name
|
42
|
-
File.unlink(cf_file)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "can override model_name specifically" do
|
46
|
-
cf_file = File.join(NSBundle.mainBundle.bundlePath, "cdq.yml")
|
47
|
-
yaml_to_file(cf_file, model_name: "foo")
|
48
|
-
config = CDQConfig.new(cf_file)
|
49
|
-
config.name.should == @bundle_name
|
50
|
-
config.database_name.should == config.name
|
51
|
-
config.model_name.should == "foo"
|
52
|
-
File.unlink(cf_file)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "constructs database_url" do
|
56
|
-
config = CDQConfig.new(nil)
|
57
|
-
config.database_url.class.should == NSURL
|
58
|
-
config.database_url.path.should =~ %r{Documents/#{@bundle_name}.sqlite$}
|
59
|
-
end
|
60
|
-
|
61
|
-
it "constructs model_url" do
|
62
|
-
config = CDQConfig.new(nil)
|
63
|
-
config.model_url.class.should == NSURL
|
64
|
-
config.model_url.path.should =~ %r{#{@bundle_name}_spec.app/#{@bundle_name}.momd$}
|
65
|
-
end
|
66
|
-
|
67
|
-
def yaml_to_file(file, hash)
|
68
|
-
contents = YAML.dump(hash)
|
69
|
-
File.open(file,'w+') { |f| f.write(contents) }
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
data/spec/cdq/context_spec.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
|
2
|
-
module CDQ
|
3
|
-
|
4
|
-
describe "CDQ Context Manager" do
|
5
|
-
|
6
|
-
before do
|
7
|
-
CDQ.cdq.setup
|
8
|
-
|
9
|
-
class << self
|
10
|
-
include CDQ
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
after do
|
15
|
-
CDQ.cdq.reset!
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
before do
|
20
|
-
@cc = CDQContextManager.new(store_manager: cdq.stores)
|
21
|
-
@context = NSManagedObjectContext.alloc.initWithConcurrencyType(NSPrivateQueueConcurrencyType)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should raise an exception if not given a store coordinator" do
|
25
|
-
c = CDQConfig.new(name: "foo")
|
26
|
-
mm = CDQModelManager.new(config: c)
|
27
|
-
sm = CDQStoreManager.new(config: c, model_manager: mm)
|
28
|
-
|
29
|
-
cc = CDQContextManager.new(store_manager: sm)
|
30
|
-
|
31
|
-
|
32
|
-
should.raise(RuntimeError) do
|
33
|
-
cc.new(NSPrivateQueueConcurrencyType)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it "can push a NSManagedObjectContext onto its stack" do
|
38
|
-
@cc.push(@context)
|
39
|
-
@cc.current.should == @context
|
40
|
-
@cc.all.should == [@context]
|
41
|
-
end
|
42
|
-
|
43
|
-
it "can pop a NSManagedObjectContext off its stack" do
|
44
|
-
@cc.push(@context)
|
45
|
-
@cc.pop.should == @context
|
46
|
-
@cc.current.should == nil
|
47
|
-
@cc.all.should == []
|
48
|
-
end
|
49
|
-
|
50
|
-
it "pushes temporarily if passed a block" do
|
51
|
-
@cc.push(@context) do
|
52
|
-
@cc.current.should == @context
|
53
|
-
end
|
54
|
-
@cc.current.should == nil
|
55
|
-
end
|
56
|
-
|
57
|
-
it "pops temporarily if passed a block" do
|
58
|
-
@cc.push(@context)
|
59
|
-
@cc.pop do
|
60
|
-
@cc.current.should == nil
|
61
|
-
end
|
62
|
-
@cc.current.should == @context
|
63
|
-
end
|
64
|
-
|
65
|
-
it "can create a new context and push it to the top of the stack" do
|
66
|
-
first = @cc.new(NSPrivateQueueConcurrencyType)
|
67
|
-
@cc.current.should.not == nil
|
68
|
-
@cc.current.concurrencyType.should == NSPrivateQueueConcurrencyType
|
69
|
-
@cc.current.parentContext.should == nil
|
70
|
-
@cc.current.persistentStoreCoordinator.should.not == nil
|
71
|
-
@cc.new(NSMainQueueConcurrencyType)
|
72
|
-
@cc.current.should.not == nil
|
73
|
-
@cc.current.concurrencyType.should == NSMainQueueConcurrencyType
|
74
|
-
@cc.current.parentContext.should == first
|
75
|
-
end
|
76
|
-
|
77
|
-
it "saves all contexts" do
|
78
|
-
root = @cc.new(NSPrivateQueueConcurrencyType)
|
79
|
-
main = @cc.new(NSMainQueueConcurrencyType)
|
80
|
-
root_saved = false
|
81
|
-
main_saved = false
|
82
|
-
root.stub!(:save) { root_saved = true }
|
83
|
-
main.stub!(:save) { main_saved = true }
|
84
|
-
@cc.save(always_wait: true)
|
85
|
-
|
86
|
-
root_saved.should == true
|
87
|
-
main_saved.should == true
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
|
2
|
-
module CDQ
|
3
|
-
describe "CDQ Managed Object" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
CDQ.cdq.setup
|
7
|
-
|
8
|
-
class << self
|
9
|
-
include CDQ
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
after do
|
14
|
-
CDQ.cdq.reset!
|
15
|
-
end
|
16
|
-
|
17
|
-
it "provides a cdq class method" do
|
18
|
-
Writer.cdq.class.should == CDQTargetedQuery
|
19
|
-
end
|
20
|
-
|
21
|
-
it "has a where method" do
|
22
|
-
Writer.where(:name).eq('eecummings').class.should == CDQTargetedQuery
|
23
|
-
end
|
24
|
-
|
25
|
-
it "has a sort_by method" do
|
26
|
-
Writer.sort_by(:name).class.should == CDQTargetedQuery
|
27
|
-
end
|
28
|
-
|
29
|
-
it "has a first method" do
|
30
|
-
eec = cdq(Writer).create(name: 'eecummings')
|
31
|
-
Writer.first.should == eec
|
32
|
-
end
|
33
|
-
|
34
|
-
it "has an all method" do
|
35
|
-
eec = cdq(Writer).create(name: 'eecummings')
|
36
|
-
Writer.all.array.should == [eec]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "can destroy itself" do
|
40
|
-
eec = cdq(Writer).create(name: 'eecummings')
|
41
|
-
eec.destroy
|
42
|
-
Writer.all.array.should == []
|
43
|
-
end
|
44
|
-
|
45
|
-
it "works with entities that do not have a specific implementation class" do
|
46
|
-
rh = cdq('Publisher').create(name: "Random House")
|
47
|
-
cdq('Publisher').where(:name).include("Random").first.should == rh
|
48
|
-
rh.destroy
|
49
|
-
cdq.save
|
50
|
-
cdq('Publisher').where(:name).include("Random").first.should == nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it "returns relationship sets which can behave like CDQRelationshipQuery objects" do
|
54
|
-
eec = Author.create(name: 'eecummings')
|
55
|
-
art = eec.articles.create(title: 'something here')
|
56
|
-
eec.articles.sort_by(:title).first.should == art
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "CDQ Managed Object scopes" do
|
60
|
-
|
61
|
-
before do
|
62
|
-
class Writer
|
63
|
-
scope :eecummings, where(:name).eq('eecummings')
|
64
|
-
scope :edgaralpoe, where(:name).eq('edgar allen poe')
|
65
|
-
end
|
66
|
-
@eec = cdq(Writer).create(name: 'eecummings')
|
67
|
-
@poe = cdq(Writer).create(name: 'edgar allen poe')
|
68
|
-
end
|
69
|
-
|
70
|
-
it "defines scopes straight on the class object" do
|
71
|
-
Writer.eecummings.array.should == [@eec]
|
72
|
-
Writer.edgaralpoe.array.should == [@poe]
|
73
|
-
end
|
74
|
-
|
75
|
-
it "also defines scopes on the cdq object" do
|
76
|
-
cdq('Writer').eecummings.array.should == [@eec]
|
77
|
-
cdq('Writer').edgaralpoe.array.should == [@poe]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|