cdq 1.0.3 → 1.0.4
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 +4 -4
- data/README.md +19 -0
- data/lib/cdq/version.rb +1 -1
- data/motion/cdq/config.rb +3 -0
- data/motion/cdq/object.rb +19 -0
- data/motion/cdq/targeted_query.rb +6 -5
- data/motion/managed_object.rb +10 -0
- metadata +2 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40687c7bb978a42e8018636e181599a5bad96e54
|
4
|
+
data.tar.gz: 1efc9104e3ecb1aa442c749746e7f492d9c09241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12e4ea59094e3ab367ba9825ff4af63b269276446c5efd285d943d0fd73b8fce45853b3dada60a86b59587fa2c8878b19e50d7caae051594377b0b6c9449c1dd
|
7
|
+
data.tar.gz: aa8b8f842e72d1ba36b05dcc25d25109403e84493b123c1a6e56152ce1d48a1b15ebee686664f07a393dd919211563100f7c54d91731aa52ff9a2565eb2d4f37
|
data/README.md
CHANGED
@@ -153,6 +153,25 @@ operations on objects use the topmost context. You just call `cdq.save`
|
|
153
153
|
and it saves the whole stack. Or you can get a list of all the contexts in
|
154
154
|
order with `cdq.contexts.all` and do more precise work.
|
155
155
|
|
156
|
+
To access the `cdq` object from a class method inside a class that is not a `CDQManagedObject`
|
157
|
+
subclass, make sure to include the `CDQ` module in your class like this:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
class MyClass
|
161
|
+
class << self
|
162
|
+
include CDQ
|
163
|
+
|
164
|
+
def my_class_method
|
165
|
+
# Do something
|
166
|
+
cdq.save
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# Elsewhere
|
172
|
+
MyClass.my_class_method
|
173
|
+
```
|
174
|
+
|
156
175
|
Settings things up the way you want is easy. Here's how you'd set it up for asynchronous
|
157
176
|
saves:
|
158
177
|
|
data/lib/cdq/version.rb
CHANGED
data/motion/cdq/config.rb
CHANGED
data/motion/cdq/object.rb
CHANGED
@@ -24,7 +24,26 @@ module CDQ
|
|
24
24
|
@@store_manager = nil
|
25
25
|
end
|
26
26
|
|
27
|
+
# Save any data and close down the contexts and store manager.
|
28
|
+
# You should be able create a new CDQConfig object and run setup
|
29
|
+
# again to attach to a different database. However, you need to be sure
|
30
|
+
# that all activity is finished, and that any exisitng model instances
|
31
|
+
# have been deallocated.
|
32
|
+
#------------------------------------------------------------------------------
|
33
|
+
def close
|
34
|
+
save
|
35
|
+
@@context_manager.reset! if @@context_manager
|
36
|
+
@@context_manager = nil
|
37
|
+
@@store_manager = nil
|
38
|
+
CDQConfig.default_config = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
# You can now pass in a CDQConfig object, which will be used instead of the
|
42
|
+
# one loaded from the cdq.yml file. However, the model file is loaded during
|
43
|
+
# the loading of the code - so it can only be overridden using the cdq.yml.
|
44
|
+
#------------------------------------------------------------------------------
|
27
45
|
def setup(opts = {})
|
46
|
+
CDQConfig.default_config = opts[:config] || nil
|
28
47
|
if opts[:context]
|
29
48
|
contexts.push(opts[:context])
|
30
49
|
return true
|
@@ -72,6 +72,7 @@ module CDQ #:nodoc:
|
|
72
72
|
# Causes execution.
|
73
73
|
#
|
74
74
|
def last(n = 1)
|
75
|
+
return nil if count == 0
|
75
76
|
result = offset(count - n).limit(n).array
|
76
77
|
n == 1 ? result.first : result
|
77
78
|
end
|
@@ -120,21 +121,21 @@ module CDQ #:nodoc:
|
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
123
|
-
# Calculates the sum of values on a given column.
|
124
|
+
# Calculates the sum of values on a given column.
|
124
125
|
#
|
125
126
|
# Author.sum(:fee) # => 6.0
|
126
127
|
def sum(column_name)
|
127
128
|
calculate(:sum, column_name)
|
128
129
|
end
|
129
|
-
|
130
|
-
# Calculates the average of values on a given column.
|
130
|
+
|
131
|
+
# Calculates the average of values on a given column.
|
131
132
|
#
|
132
133
|
# Author.average(:fee) # => 2.0
|
133
134
|
def average(column_name)
|
134
135
|
calculate(:average, column_name)
|
135
136
|
end
|
136
137
|
|
137
|
-
# Calculates the minimum of values on a given column.
|
138
|
+
# Calculates the minimum of values on a given column.
|
138
139
|
#
|
139
140
|
# Author.min(:fee) # => 1.0
|
140
141
|
def min(column_name)
|
@@ -142,7 +143,7 @@ module CDQ #:nodoc:
|
|
142
143
|
end
|
143
144
|
alias :minimum :min
|
144
145
|
|
145
|
-
# Calculates the maximum of values on a given column.
|
146
|
+
# Calculates the maximum of values on a given column.
|
146
147
|
#
|
147
148
|
# Author.max(:fee) # => 3.0
|
148
149
|
def max(column_name)
|
data/motion/managed_object.rb
CHANGED
@@ -155,6 +155,16 @@ class CDQManagedObject < CoreDataQueryManagedObjectBase
|
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
+
# Opt-in support for motion_print
|
159
|
+
def motion_print(mp, options)
|
160
|
+
if respond_to? :attributes
|
161
|
+
"OID: " + mp.colorize(oid.gsub('"',''), options[:force_color]) + "\n" + mp.l_hash(attributes, options)
|
162
|
+
else
|
163
|
+
# old colorless method, still more informative than nothing
|
164
|
+
log
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
158
168
|
def ordered_set?(name)
|
159
169
|
# isOrdered is returning 0/1 instead of documented BOOL
|
160
170
|
ordered = entity.relationshipsByName[name].isOrdered
|
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: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- infinitered
|
@@ -9,15 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-xcdm
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0.0'
|
21
18
|
- - ">="
|
22
19
|
- !ruby/object:Gem::Version
|
23
20
|
version: 0.0.9
|
@@ -25,9 +22,6 @@ dependencies:
|
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
27
24
|
requirements:
|
28
|
-
- - "~>"
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '0.0'
|
31
25
|
- - ">="
|
32
26
|
- !ruby/object:Gem::Version
|
33
27
|
version: 0.0.9
|