cdq 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +21 -20
- data/lib/cdq/version.rb +1 -1
- data/motion/cdq/query.rb +32 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTVmOGNjMzAwMmQzYTdjMDMyYjViYWU2MGEzYTc1MTdiNGJiMzM4OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjRmYzhkNDk1MmI1ZWFiODg1YTkzNmUwMTZmNGU5NTVhYzFiOWE3YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDliNjIxOWQxMTMzODA2NTcxMmQxMTQ0Zjg3NGI2OTA4YTczZTkwZTdmN2Rm
|
10
|
+
MzViMGM3ZDRhZTU1MDliN2E3ZDQ4YTJiMmRhNzZmNjlhOWM2MTI3NzJlYmIz
|
11
|
+
ZDRkNzEzMDhiNTZjZTg3MGFhMmE4MGU3MjRlMDNlY2FjZTgzNzk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGZiYTcyYjlkNjU0ZWZjZDk1Y2MyODBhN2JlNDg5ZDc3ZDU0Y2I4ZjgwNjUx
|
14
|
+
NTM1MmMwNTlmZTNlMWE1ZGIyNWFmNjI3YTVmNjk5NGI0NDFlZWVlNzc4MmI1
|
15
|
+
YjQ5ZDVmMzI0MTUzNTdhOTdlZjMxNjQ5OGM2NDIwOTJlMDczNDc=
|
data/README.md
CHANGED
@@ -19,18 +19,18 @@ genetic traces, so thanks to @alloy for sharing his work and letting me learn
|
|
19
19
|
so much.
|
20
20
|
|
21
21
|
CDQ aims to streamline the process of getting you up and running Core Data, while
|
22
|
-
avoiding too much abstraction or method pollution on top of the SDK. While it
|
23
|
-
borrows many ideas from ActiveRecord (especially AREL), it is designed to
|
24
|
-
harmonize with Core Data's way of doing things first.
|
22
|
+
avoiding too much abstraction or method pollution on top of the SDK. While it
|
23
|
+
borrows many ideas from ActiveRecord (especially AREL), it is designed to
|
24
|
+
harmonize with Core Data's way of doing things first.
|
25
25
|
|
26
26
|
I am actively developing and improving CDQ (updated February 2014) so if you have
|
27
|
-
trouble or find a bug, please open a ticket!
|
27
|
+
trouble or find a bug, please open a ticket!
|
28
28
|
|
29
29
|
### Why use a static Data Model?
|
30
30
|
|
31
31
|
By using a real data model file that gets compiled and included in your bundle,
|
32
32
|
you can take advantage of automatic migration, which simplifies managing your
|
33
|
-
schema as it grows, if you can follow a few [simple rules](https://developer.apple.com/library/ios/documentation/cocoa/conceptual/CoreDataVersioning/Articles/vmLightweightMigration.html#//apple_ref/doc/uid/TP40004399-CH4-SW2).
|
33
|
+
schema as it grows, if you can follow a few [simple rules](https://developer.apple.com/library/ios/documentation/cocoa/conceptual/CoreDataVersioning/Articles/vmLightweightMigration.html#//apple_ref/doc/uid/TP40004399-CH4-SW2).
|
34
34
|
|
35
35
|
## Installing
|
36
36
|
|
@@ -71,7 +71,7 @@ gem 'cdq', git: 'git://github.com/infinitered/cdq.git'
|
|
71
71
|
You will need a data model file. If you've created one in XCode, move or copy
|
72
72
|
it to your resources file and make sure it's named the same as your RubyMotion
|
73
73
|
project. If you're using `ruby-xcdm` (which I highly recommend) then it will
|
74
|
-
create the datamodel file automatically and put it in the right place.
|
74
|
+
create the datamodel file automatically and put it in the right place.
|
75
75
|
|
76
76
|
Now include the setup code in your ```app_delegate.rb``` file:
|
77
77
|
|
@@ -88,13 +88,13 @@ end
|
|
88
88
|
|
89
89
|
That's it! You can create specific implementation classes for your entities if
|
90
90
|
you want, but it's not required. You can start running queries on the console or
|
91
|
-
in your code right away.
|
91
|
+
in your code right away.
|
92
92
|
|
93
93
|
## Schema
|
94
94
|
|
95
|
-
The best way to use CDQ is together with ruby-xcdm, which is installed as a
|
95
|
+
The best way to use CDQ is together with ruby-xcdm, which is installed as a
|
96
96
|
dependency. For the full docs, see its [github page](http://github.com/infinitered/ruby-xcdm),
|
97
|
-
but here's a taste. Schema files are found in the "schemas" directory within your
|
97
|
+
but here's a taste. Schema files are found in the "schemas" directory within your
|
98
98
|
app root, and they are versioned for automatic migrations, and this is what they look like:
|
99
99
|
|
100
100
|
```ruby
|
@@ -114,7 +114,7 @@ app root, and they are versioned for automatic migrations, and this is what they
|
|
114
114
|
entity "Author" do
|
115
115
|
float :fee
|
116
116
|
string :name, optional: false
|
117
|
-
has_many :articles
|
117
|
+
has_many :articles
|
118
118
|
end
|
119
119
|
|
120
120
|
end
|
@@ -128,16 +128,16 @@ Managing NSManagedObjectContext objects in Core Data can be tricky, especially
|
|
128
128
|
if you are trying to take advantage of nested contexts for better threading
|
129
129
|
behavior. One of the best parts of CDQ is that it handles contexts for you
|
130
130
|
relatively seamlessly. If you have a simple app, you may never need to worry
|
131
|
-
about contexts at all.
|
131
|
+
about contexts at all.
|
132
132
|
|
133
133
|
### Nested Contexts
|
134
134
|
|
135
|
-
For a great discussion of why you might want to use nested contexts, see [here](http://www.cocoanetics.com/2012/07/multi-context-coredata/).
|
135
|
+
For a great discussion of why you might want to use nested contexts, see [here](http://www.cocoanetics.com/2012/07/multi-context-coredata/).
|
136
136
|
|
137
137
|
CDQ maintains a stack of contexts (one stack per thread), and by default, all
|
138
138
|
operations on objects use the topmost context. You just call ```cdq.save```
|
139
139
|
and it saves the whole stack. Or you can get a list of all the contexts in
|
140
|
-
order with ```cdq.contexts.all``` and do more precise work.
|
140
|
+
order with ```cdq.contexts.all``` and do more precise work.
|
141
141
|
|
142
142
|
Settings things up the way you want is easy. Here's how you'd set it up for asynchronous
|
143
143
|
saves:
|
@@ -147,7 +147,7 @@ saves:
|
|
147
147
|
cdq.contexts.new(NSMainQueueConcurrencyType)
|
148
148
|
```
|
149
149
|
|
150
|
-
This pushes a private queue context onto the bottom of the stack, then a main queue context on top of it.
|
150
|
+
This pushes a private queue context onto the bottom of the stack, then a main queue context on top of it.
|
151
151
|
Since the main queue is on top, all your data operations will use that. ```cdq.save``` then saves the
|
152
152
|
main context, and schedules a save on the root context.
|
153
153
|
|
@@ -202,7 +202,7 @@ able to use them easily when debugging from the console, or in unit tests.
|
|
202
202
|
|
203
203
|
All of these queries are infinitely daisy-chainable, and almost everything is
|
204
204
|
possible to do using only chained methods, no need to drop into NSPredicate format
|
205
|
-
strings unless you want to.
|
205
|
+
strings unless you want to.
|
206
206
|
|
207
207
|
Here are some examples. See the [cheat
|
208
208
|
sheet](https://github.com/infinitered/cdq/wiki/CDQ-Cheat-Sheet) for a complete
|
@@ -211,7 +211,7 @@ list.
|
|
211
211
|
### Conditions
|
212
212
|
|
213
213
|
```ruby
|
214
|
-
Author.where(:name).eq('Shakespeare')
|
214
|
+
Author.where(:name).eq('Shakespeare')
|
215
215
|
Author.where(:publish_count).gt(10)
|
216
216
|
Author.where(name: 'Shakespeare', publish_count: 15)
|
217
217
|
Author.where("name LIKE '%@'", '%kesp%')
|
@@ -221,7 +221,8 @@ list.
|
|
221
221
|
|
222
222
|
```ruby
|
223
223
|
Author.sort_by(:created_at).limit(1).offset(10)
|
224
|
-
Author.sort_by(:created_at, :descending)
|
224
|
+
Author.sort_by(:created_at, order: :descending)
|
225
|
+
Author.sort_by(:created_at, case_insensitive: true)
|
225
226
|
```
|
226
227
|
|
227
228
|
### Conjunctions
|
@@ -241,7 +242,7 @@ list.
|
|
241
242
|
|
242
243
|
### Fetching
|
243
244
|
|
244
|
-
Like ActiveRecord, CDQ will not run a fetch until you actually request specific
|
245
|
+
Like ActiveRecord, CDQ will not run a fetch until you actually request specific
|
245
246
|
objects. There are several methods for getting at the data:
|
246
247
|
|
247
248
|
* ```array```
|
@@ -254,7 +255,7 @@ objects. There are several methods for getting at the data:
|
|
254
255
|
## Dedicated Models
|
255
256
|
|
256
257
|
If you're using CDQ in a brand new project, you'll probably want to use
|
257
|
-
dedicated model classes for your entities.
|
258
|
+
dedicated model classes for your entities.
|
258
259
|
familiar-looking and natural syntax for queries and scopes:
|
259
260
|
|
260
261
|
```ruby
|
@@ -305,7 +306,7 @@ including the model ```CDQ``` into your classes. To use an entity without a
|
|
305
306
|
model class, just pass its name as a string into the master method, like so
|
306
307
|
|
307
308
|
```ruby
|
308
|
-
cdq('Author').where(:name).eq('Shakespeare')
|
309
|
+
cdq('Author').where(:name).eq('Shakespeare')
|
309
310
|
cdq('Author').where(:publish_count).gt(10)
|
310
311
|
cdq('Author').sort_by(:created_at).limit(1).offset(10)
|
311
312
|
```
|
data/lib/cdq/version.rb
CHANGED
data/motion/cdq/query.rb
CHANGED
@@ -96,16 +96,43 @@ module CDQ
|
|
96
96
|
# old ones.
|
97
97
|
#
|
98
98
|
# @param key The attribute to sort on
|
99
|
-
# @param
|
100
|
-
#
|
101
|
-
|
102
|
-
|
99
|
+
# @param options Optional options.
|
100
|
+
#
|
101
|
+
# Options include:
|
102
|
+
# order: If :descending or (or :desc), order is descrnding. Otherwise,
|
103
|
+
# it is ascending.
|
104
|
+
# case_insensitive: True or false. If true, the sort descriptor is
|
105
|
+
# built using <tt>localizedCaseInsensitiveCompare</tt>
|
106
|
+
#
|
107
|
+
def sort_by(key, options = {})
|
108
|
+
# backwards compat: if options is not a hash, it is a sort ordering.
|
109
|
+
unless options.is_a?Hash
|
110
|
+
sort_order = options
|
111
|
+
options = {
|
112
|
+
order: sort_order,
|
113
|
+
case_insensitive: false,
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
options = {
|
118
|
+
order: :ascending,
|
119
|
+
}.merge(options)
|
120
|
+
|
121
|
+
order = options[:order].to_s
|
122
|
+
|
123
|
+
if order[0,4].downcase == 'desc'
|
103
124
|
ascending = false
|
104
125
|
else
|
105
126
|
ascending = true
|
106
127
|
end
|
107
128
|
|
108
|
-
|
129
|
+
if options[:case_insensitive]
|
130
|
+
descriptor = NSSortDescriptor.sortDescriptorWithKey(key, ascending: ascending, selector: "localizedCaseInsensitiveCompare:")
|
131
|
+
else
|
132
|
+
descriptor = NSSortDescriptor.sortDescriptorWithKey(key, ascending: ascending)
|
133
|
+
end
|
134
|
+
|
135
|
+
clone(sort_descriptors: @sort_descriptors + [descriptor])
|
109
136
|
end
|
110
137
|
|
111
138
|
# Return an NSFetchRequest that will implement this query
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- infinitered
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-xcdm
|