cdq 0.1.6 → 0.1.7
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/README.md +3 -0
- data/lib/cdq.rb +2 -0
- data/lib/cdq/version.rb +1 -1
- data/motion/cdq/model.rb +26 -0
- data/motion/cdq/object.rb +7 -0
- data/motion/cdq/targeted_query.rb +61 -0
- data/motion/managed_object.rb +2 -2
- data/templates/init/spec/helpers/cdq.rb +6 -0
- data/templates/model/spec/models/name.rb +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDQ0YWQwNGU1YWNkOWRhN2Y2YmYwY2QyMDVhNDdjYTYzYzlkNGIyNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWEyZjUyNzg2OGM0ZDMyNWQzOTE1NWRhYmY4NzY5YmYzZWM1ZTU2Nw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTA3YWIyN2IwMDUzYzIxMjVhNTI0OTkzMzNmNmQwZDgxMGZlZTc4MTNiNTI5
|
10
|
+
Mzg3YjczZDFlMTE5YTlkNWRhYmZkNzFjNTQ5MTdmYTM1OTk2MWU0NDJlMDlj
|
11
|
+
ZTU2MzY5MjNjNGQ5MzJjMTZkMjhhYTU1MDY4OTFiODAwMjE1MzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDM4YTVkZjlhMzVhZjcyNjAzMzc4NTI5YjI4NjAyMWVlNjZmYzUwYmRmZTFh
|
14
|
+
MDU3YTI3YjI0N2FmMDE0MGZkMDYzYmM0NTZiY2E3MTMyYWM3NmU5ZDBmYjFk
|
15
|
+
ZDI1MDJhZGEwMjJkNjIwYjJkM2NjMWQxYmNhODIxMGE4ODcwNjk=
|
data/README.md
CHANGED
@@ -23,6 +23,9 @@ avoiding too much abstraction or method pollution on top of the SDK. While it
|
|
23
23
|
borrows many ideas from ActiveRecord (especially AREL), it is designed to
|
24
24
|
harmonize with Core Data's way of doing things first.
|
25
25
|
|
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!
|
28
|
+
|
26
29
|
### Why use a static Data Model?
|
27
30
|
|
28
31
|
By using a real data model file that gets compiled and included in your bundle,
|
data/lib/cdq.rb
CHANGED
data/lib/cdq/version.rb
CHANGED
data/motion/cdq/model.rb
CHANGED
@@ -17,6 +17,32 @@ module CDQ
|
|
17
17
|
!@current && @config.model_url.nil?
|
18
18
|
end
|
19
19
|
|
20
|
+
def log(log_type = nil)
|
21
|
+
out = "\n\n MODELS"
|
22
|
+
out << "\n Model | count |"
|
23
|
+
line = "\n - - - - - - - - - - - - - | - - - - - |"
|
24
|
+
out << line
|
25
|
+
|
26
|
+
self.current.entities.each do |entity|
|
27
|
+
out << "\n #{entity.name.ljust(25)}|"
|
28
|
+
out << " #{CDQ.cdq(entity.name).count.to_s.rjust(9)} |"
|
29
|
+
end
|
30
|
+
|
31
|
+
out << line
|
32
|
+
|
33
|
+
entities = CDQ.cdq.models.current.entities
|
34
|
+
if entities && (entity_count = entities.length) && entity_count > 0
|
35
|
+
out << "\n#{entity_count} models"
|
36
|
+
out << "\n\nYou can log a model like so: #{self.current.entities.first.name}.log"
|
37
|
+
end
|
38
|
+
|
39
|
+
if log_type == :string
|
40
|
+
out
|
41
|
+
else
|
42
|
+
NSLog out
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
20
46
|
private
|
21
47
|
|
22
48
|
def load_model
|
data/motion/cdq/object.rb
CHANGED
@@ -41,12 +41,19 @@ module CDQ
|
|
41
41
|
contexts.save(*args)
|
42
42
|
end
|
43
43
|
|
44
|
+
def find(oid)
|
45
|
+
url = NSURL.URLWithString(oid)
|
46
|
+
object_id = stores.current.managedObjectIDForURIRepresentation(url)
|
47
|
+
contexts.current.existingObjectWithID(object_id, error: nil)
|
48
|
+
end
|
49
|
+
|
44
50
|
protected
|
45
51
|
|
46
52
|
def with_error_object(default, &block)
|
47
53
|
error = Pointer.new(:object)
|
48
54
|
result = block.call(error)
|
49
55
|
if error[0]
|
56
|
+
p error[0].debugDescription
|
50
57
|
raise "Error while fetching: #{error[0].debugDescription}"
|
51
58
|
end
|
52
59
|
result || default
|
@@ -153,8 +153,69 @@ module CDQ #:nodoc:
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
+
def log(log_type = nil)
|
157
|
+
out = "\n\n ATTRIBUTES"
|
158
|
+
out << " \n Name | type | default |"
|
159
|
+
line = " \n- - - - - - - - - - - | - - - - - - - - - - | - - - - - - - - - - - - - - - |"
|
160
|
+
out << line
|
161
|
+
|
162
|
+
abn = entity_description.attributesByName
|
163
|
+
rbn = entity_description.relationshipsByName
|
164
|
+
|
165
|
+
abn.each do |name, desc|
|
166
|
+
out << " \n #{name.ljust(21)}|"
|
167
|
+
out << " #{desc.attributeValueClassName.ljust(20)}|"
|
168
|
+
out << " #{desc.defaultValue.to_s.ljust(30)}|"
|
169
|
+
end
|
170
|
+
|
171
|
+
out << line
|
172
|
+
out << "\n\n"
|
173
|
+
|
174
|
+
self.each do |o|
|
175
|
+
out << "OID: "
|
176
|
+
out << oid(o)
|
177
|
+
out << "\n"
|
178
|
+
|
179
|
+
awidth = abn.keys.map(&:length).max
|
180
|
+
rwidth = rbn.keys.map(&:length).max
|
181
|
+
width = [awidth, rwidth].max
|
182
|
+
|
183
|
+
abn.each do |name, desc|
|
184
|
+
out << " #{name.ljust(width)} : "
|
185
|
+
out << o.send(name).inspect[0,95 - width]
|
186
|
+
out << "\n"
|
187
|
+
end
|
188
|
+
rbn.each do |name, desc|
|
189
|
+
rel = CDQRelationshipQuery.new(o, name)
|
190
|
+
if desc.isToMany
|
191
|
+
out << " #{name.ljust(width)} : "
|
192
|
+
out << rel.count.to_s
|
193
|
+
out << ' (count)'
|
194
|
+
else
|
195
|
+
out << " #{name.ljust(width)} : "
|
196
|
+
out << oid(rel.first)
|
197
|
+
end
|
198
|
+
out << "\n"
|
199
|
+
end
|
200
|
+
out << "\n"
|
201
|
+
end
|
202
|
+
|
203
|
+
if log_type == :string
|
204
|
+
out
|
205
|
+
else
|
206
|
+
NSLog out
|
207
|
+
end
|
208
|
+
|
209
|
+
rescue Exception => e
|
210
|
+
p e
|
211
|
+
end
|
212
|
+
|
156
213
|
private
|
157
214
|
|
215
|
+
def oid(obj)
|
216
|
+
obj ? obj.objectID.URIRepresentation.absoluteString.inspect : "nil"
|
217
|
+
end
|
218
|
+
|
158
219
|
def named_scopes
|
159
220
|
@@named_scopes ||= {}
|
160
221
|
@@named_scopes[@entity_description] ||= {}
|
data/motion/managed_object.rb
CHANGED
@@ -49,11 +49,11 @@ class CDQManagedObject < CoreDataQueryManagedObjectBase
|
|
49
49
|
cdq.scope(name, query, &block)
|
50
50
|
if query
|
51
51
|
self.class.send(:define_method, name) do
|
52
|
-
query
|
52
|
+
where(query)
|
53
53
|
end
|
54
54
|
else
|
55
55
|
self.class.send(:define_method, name) do |*args|
|
56
|
-
block.call(*args)
|
56
|
+
where(block.call(*args))
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
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.7
|
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-02-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-xcdm
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- motion/cdq.rb
|
74
74
|
- motion/managed_object.rb
|
75
75
|
- templates/init/schemas/0001_initial.rb
|
76
|
+
- templates/init/spec/helpers/cdq.rb
|
76
77
|
- templates/model/app/models/name.rb
|
77
78
|
- templates/model/spec/models/name.rb
|
78
79
|
- vendor/cdq/ext/CoreDataQueryManagedObjectBase.m
|