cdq 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTI5YzdjODkzN2VkZTA0Y2I2Mzk0YTkwMjRlMTY2M2M3ODVkNjgzMg==
4
+ NDQ0YWQwNGU1YWNkOWRhN2Y2YmYwY2QyMDVhNDdjYTYzYzlkNGIyNA==
5
5
  data.tar.gz: !binary |-
6
- OTQ2YjViOTcxNzJlNzY5MTE4ZWZhMGJkZDZjM2YyNTVhZTMxMWMzYQ==
6
+ NWEyZjUyNzg2OGM0ZDMyNWQzOTE1NWRhYmY4NzY5YmYzZWM1ZTU2Nw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDU5ZWQ3M2UyY2UzM2Q1MGI1YWIyMTdiN2JkMzBiYzMxYTdmYzc1YTk4YjYz
10
- YjcxY2RkMzE0MzEyMmMzY2RhZTUxMDk1MzM2ZjBlYmU1NzY3MTc2Nzc0Mjc4
11
- ZjBhZjI3MTEzNmIxNzZiNDA3ODE4ZjRhOTFiMmYzYjYwMzQ1ZDU=
9
+ NTA3YWIyN2IwMDUzYzIxMjVhNTI0OTkzMzNmNmQwZDgxMGZlZTc4MTNiNTI5
10
+ Mzg3YjczZDFlMTE5YTlkNWRhYmZkNzFjNTQ5MTdmYTM1OTk2MWU0NDJlMDlj
11
+ ZTU2MzY5MjNjNGQ5MzJjMTZkMjhhYTU1MDY4OTFiODAwMjE1MzY=
12
12
  data.tar.gz: !binary |-
13
- M2M3OWFiOGI4OWRmYzE0ZGNjZWVlMjQ3NmRkNGJkNjA4YTRkMjRkMmM5MjZk
14
- NDFjMzBhY2FjNTNhNDgzNDRjOTgxYzU5YjAzNTc4MTA2NjAwZjg5ZjE2OWU4
15
- MzFhYWYwZGQ5OGI4N2JjZjMxN2Y5YWZlODFlODdiZWIxZDYwYmI=
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
@@ -5,6 +5,8 @@ end
5
5
 
6
6
  require 'ruby-xcdm'
7
7
 
8
+ ENV['COLUMNS'] ||= `tput cols`.strip
9
+
8
10
  Motion::Project::App.setup do |app|
9
11
  parent = File.join(File.dirname(__FILE__), '..')
10
12
  app.files.unshift(Dir.glob(File.join(parent, "motion/cdq/**/*.rb")))
data/lib/cdq/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module CDQ
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
  end
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] ||= {}
@@ -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
@@ -0,0 +1,6 @@
1
+
2
+ module Bacon
3
+ class Context
4
+ include CDQ
5
+ end
6
+ end
@@ -1,7 +1,9 @@
1
1
  describe '<%= @name_camel_case %>' do
2
2
 
3
3
  before do
4
- include CDQ
4
+ class << self
5
+ include CDQ
6
+ end
5
7
  cdq.setup
6
8
  end
7
9
 
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.6
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-01-24 00:00:00.000000000 Z
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