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.
@@ -1,13 +0,0 @@
1
- class AppDelegate
2
- include CDQ
3
-
4
- def application(application, didFinishLaunchingWithOptions:launchOptions)
5
- cdq.setup
6
- true
7
- end
8
- end
9
-
10
- class TopLevel
11
- include CDQ
12
- end
13
-
@@ -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
-
@@ -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>
File without changes
@@ -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
-
@@ -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
@@ -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