Parsistence 0.3.21 → 0.4.0
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 +7 -0
- data/README.md +15 -2
- data/lib/Parsistence/Model.rb +26 -21
- data/lib/Parsistence/Query.rb +28 -31
- data/lib/Parsistence/version.rb +1 -1
- metadata +8 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d583354bffa09432ccd74e8ab9c49236a42f2003
|
4
|
+
data.tar.gz: 493b93622645fa135fd2871eba31ac21fd26005b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46f1f1af11f8e534e93902ac4c7fa3ef80ba34c39091f21928de39aeccca2ba614c07312c45a9bb28df3c9f8d98318d787e35004a18f71eb3557850997c32794
|
7
|
+
data.tar.gz: 77a550efaee075446f9d5c9bbe2d5032e32aee7e222bf55d618538b0cbfabd8b7e77368618ba21ed2843d193597bca7b562c220b580169db99996e3bcb570a39
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# About
|
2
2
|
|
3
|
-
Parsistence provides an ActiveRecord/Persistence.js pattern to your Parse.com models on RubyMotion.
|
3
|
+
Parsistence provides an ActiveRecord/Persistence.js pattern to your Parse.com models on RubyMotion.
|
4
4
|
It's an early fork from [ParseModel](https://github.com/adelevie/ParseModel) by
|
5
5
|
Alan deLevie but goes a different direction with its implementation.
|
6
6
|
|
@@ -31,6 +31,19 @@ p.saveEventually
|
|
31
31
|
|
32
32
|
`Parsistence::Model` objects will `respond_to?` to all methods available to [`PFObject`](https://parse.com/docs/ios/api/Classes/PFObject.html) in the Parse iOS SDK, as well as 'fields' getters and setters. You can also access the `PFObject` instance directly with, you guessed it, `Parsistence::Model#PFObject`.
|
33
33
|
|
34
|
+
If you pass in a PFObject instance, it'll use that:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
p = Post.new(pf_post)
|
38
|
+
```
|
39
|
+
|
40
|
+
If you pass in a hash, it'll set properties automatically:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
p = Post.new(title: "Awesome")
|
44
|
+
p.title # => "Awesome"
|
45
|
+
```
|
46
|
+
|
34
47
|
### Users
|
35
48
|
|
36
49
|
```ruby
|
@@ -215,4 +228,4 @@ To install the Parse iOS SDK in your RubyMotion project, read [this](http://www.
|
|
215
228
|
|
216
229
|
## License
|
217
230
|
|
218
|
-
See LICENSE.txt
|
231
|
+
See LICENSE.txt
|
data/lib/Parsistence/Model.rb
CHANGED
@@ -1,23 +1,28 @@
|
|
1
1
|
module Parsistence
|
2
2
|
module Model
|
3
3
|
attr_accessor :PFObject, :errors
|
4
|
-
|
4
|
+
|
5
5
|
RESERVED_KEYS = [:objectId]
|
6
6
|
|
7
7
|
def initialize(pf=nil)
|
8
|
-
if pf
|
8
|
+
if pf && !pf.is_a?(Hash)
|
9
|
+
pf = pf.to_object if pf.is_a?(Pointer)
|
9
10
|
self.PFObject = pf
|
10
11
|
else
|
11
12
|
self.PFObject = PFObject.objectWithClassName(self.class.to_s)
|
12
13
|
end
|
13
|
-
|
14
|
+
if pf.is_a?(Hash)
|
15
|
+
pf.each do |k, v|
|
16
|
+
self.send("#{k}=", v) if self.respond_to?("#{k}=")
|
17
|
+
end
|
18
|
+
end
|
14
19
|
self
|
15
20
|
end
|
16
|
-
|
21
|
+
|
17
22
|
def method_missing(method, *args, &block)
|
18
23
|
method = method.to_sym
|
19
24
|
setter = false
|
20
|
-
|
25
|
+
|
21
26
|
if setter?(method)
|
22
27
|
setter = true
|
23
28
|
method = method.split("=")[0].to_sym
|
@@ -55,7 +60,7 @@ module Parsistence
|
|
55
60
|
end
|
56
61
|
|
57
62
|
# Override of ruby's respond_to?
|
58
|
-
#
|
63
|
+
#
|
59
64
|
# @param [Symbol] method
|
60
65
|
# @return [Bool] true/false
|
61
66
|
def respond_to?(method)
|
@@ -68,7 +73,7 @@ module Parsistence
|
|
68
73
|
return true if fields.include?(method) || relations.include?(method)
|
69
74
|
|
70
75
|
super
|
71
|
-
end
|
76
|
+
end
|
72
77
|
|
73
78
|
def fields
|
74
79
|
self.class.send(:get_fields)
|
@@ -126,12 +131,12 @@ module Parsistence
|
|
126
131
|
elsif belongs_to.include?(field.to_sym)
|
127
132
|
return setField(field, value)
|
128
133
|
end
|
129
|
-
|
134
|
+
|
130
135
|
raise "Parsistence Exception: Invalid relation name #{field} for object #{self.class.to_s}"
|
131
136
|
end
|
132
137
|
|
133
138
|
# Returns all of the attributes of the Model
|
134
|
-
#
|
139
|
+
#
|
135
140
|
# @return [Hash] attributes of Model
|
136
141
|
def attributes
|
137
142
|
attributes = {}
|
@@ -142,7 +147,7 @@ module Parsistence
|
|
142
147
|
end
|
143
148
|
|
144
149
|
# Sets the attributes of the Model
|
145
|
-
#
|
150
|
+
#
|
146
151
|
# @param [Hash] attrs to set on the Model
|
147
152
|
# @return [Hash] that you gave it
|
148
153
|
# @note will throw an error if a key is invalid
|
@@ -151,7 +156,7 @@ module Parsistence
|
|
151
156
|
if v.respond_to?(:each) && !v.is_a?(PFObject)
|
152
157
|
self.attributes = v
|
153
158
|
elsif self.respond_to? "#{k}="
|
154
|
-
self.send("#{k}=", v)
|
159
|
+
self.send("#{k}=", v)
|
155
160
|
else
|
156
161
|
setField(k, v) unless k.nil?
|
157
162
|
end
|
@@ -163,7 +168,7 @@ module Parsistence
|
|
163
168
|
# @note calls before/after_save hooks
|
164
169
|
# @note before_save MUST return true, or save will not be called on PFObject
|
165
170
|
# @note does not save if validations fail
|
166
|
-
#
|
171
|
+
#
|
167
172
|
# @return [Bool] true/false
|
168
173
|
def save
|
169
174
|
saved = false
|
@@ -232,10 +237,10 @@ module Parsistence
|
|
232
237
|
@errors ||= {}
|
233
238
|
if presenceValidations.include?(field) && (value.nil? || value == "")
|
234
239
|
messages = presenceValidationMessages
|
235
|
-
if messages.include?(field)
|
240
|
+
if messages.include?(field)
|
236
241
|
@errors[field] = messages[field]
|
237
242
|
else
|
238
|
-
@errors[field] = "#{field} can't be blank"
|
243
|
+
@errors[field] = "#{field} can't be blank"
|
239
244
|
end
|
240
245
|
end
|
241
246
|
end
|
@@ -261,7 +266,7 @@ module Parsistence
|
|
261
266
|
end
|
262
267
|
|
263
268
|
module ClassMethods
|
264
|
-
|
269
|
+
|
265
270
|
# set the fields for the current Model
|
266
271
|
# used in method_missing
|
267
272
|
#
|
@@ -269,7 +274,7 @@ module Parsistence
|
|
269
274
|
def fields(*args)
|
270
275
|
args.each {|arg| field(arg)}
|
271
276
|
end
|
272
|
-
|
277
|
+
|
273
278
|
# set a field for the current Model
|
274
279
|
#
|
275
280
|
# @param [Symbol] name of field
|
@@ -279,7 +284,7 @@ module Parsistence
|
|
279
284
|
@fields << name.to_sym
|
280
285
|
@fields.uniq!
|
281
286
|
end
|
282
|
-
|
287
|
+
|
283
288
|
def get_fields
|
284
289
|
@fields ||= []
|
285
290
|
end
|
@@ -341,7 +346,7 @@ module Parsistence
|
|
341
346
|
end
|
342
347
|
|
343
348
|
# require a certain field to be present (not nil And not an empty String)
|
344
|
-
#
|
349
|
+
#
|
345
350
|
# @param [Symbol, Hash] field and options (now only has message)
|
346
351
|
def validates_presence_of(field, opts={})
|
347
352
|
@presenceValidationMessages ||= {}
|
@@ -352,7 +357,7 @@ module Parsistence
|
|
352
357
|
def get_presence_validations
|
353
358
|
@presenceValidations ||= {}
|
354
359
|
end
|
355
|
-
|
360
|
+
|
356
361
|
def get_presence_validation_messages
|
357
362
|
@presenceValidationMessages ||= {}
|
358
363
|
end
|
@@ -362,10 +367,10 @@ module Parsistence
|
|
362
367
|
@presenceValidations << field
|
363
368
|
end
|
364
369
|
end
|
365
|
-
|
370
|
+
|
366
371
|
def self.included(base)
|
367
372
|
base.extend(ClassMethods)
|
368
373
|
end
|
369
374
|
|
370
375
|
end
|
371
|
-
end
|
376
|
+
end
|
data/lib/Parsistence/Query.rb
CHANGED
@@ -101,13 +101,13 @@ module Parsistence
|
|
101
101
|
elsif @cached == false
|
102
102
|
query.cachePolicy = KPFCachePolicyNetworkOnly
|
103
103
|
else
|
104
|
-
query.cachePolicy = self.class.cache_policy if self.class.cache_policy
|
104
|
+
query.cachePolicy = self.class.cache_policy if self.class.cache_policy
|
105
105
|
end
|
106
106
|
|
107
107
|
@includes.each do |include|
|
108
108
|
query.includeKey(include)
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
@conditions.each do |key, value|
|
112
112
|
checkKey key
|
113
113
|
value = value.PFObject if value.respond_to?(:PFObject)
|
@@ -178,29 +178,28 @@ module Parsistence
|
|
178
178
|
|
179
179
|
def fetch(&callback)
|
180
180
|
if @limit && @limit == 1
|
181
|
-
fetchOne(&callback)
|
181
|
+
fetchOne(&callback)
|
182
182
|
else
|
183
183
|
fetchAll(&callback)
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
self
|
187
187
|
end
|
188
188
|
|
189
189
|
# @deprecated
|
190
190
|
# Grab all results that match query
|
191
|
-
#
|
191
|
+
#
|
192
192
|
# @param [Block] callback block
|
193
193
|
# @return [Nil]
|
194
|
-
#
|
194
|
+
#
|
195
195
|
# (see #all)
|
196
196
|
def fetchAll(&callback)
|
197
197
|
query = createQuery
|
198
|
-
|
198
|
+
|
199
199
|
myKlass = self.klass
|
200
|
-
query.findObjectsInBackgroundWithBlock (
|
200
|
+
query.findObjectsInBackgroundWithBlock (->(items) {
|
201
201
|
modelItems = []
|
202
202
|
modelItems = items.map! { |item| myKlass.new(item) } if items
|
203
|
-
callback.call(modelItems, error) if callback.arity == 2
|
204
203
|
callback.call(modelItems) if callback.arity == 1
|
205
204
|
callback.call if callback.arity == 0
|
206
205
|
})
|
@@ -210,21 +209,19 @@ module Parsistence
|
|
210
209
|
|
211
210
|
# @deprecated
|
212
211
|
# Grab first result that matches query
|
213
|
-
#
|
212
|
+
#
|
214
213
|
# @param [Block] callback block
|
215
214
|
# @return [Nil]
|
216
|
-
#
|
215
|
+
#
|
217
216
|
# (see #first)
|
218
217
|
def fetchOne(&callback)
|
219
218
|
limit(0, 1)
|
220
219
|
query = createQuery
|
221
|
-
|
220
|
+
|
222
221
|
myKlass = self.klass
|
223
|
-
query.getFirstObjectInBackgroundWithBlock (lambda { |item
|
224
|
-
|
225
|
-
callback.call(
|
226
|
-
callback.call(modelItem) if callback.arity == 1
|
227
|
-
callback.call if callback.arity == 0
|
222
|
+
query.getFirstObjectInBackgroundWithBlock (lambda { |item|
|
223
|
+
item = myKlass.new(item) if item
|
224
|
+
callback.call(item)
|
228
225
|
})
|
229
226
|
|
230
227
|
self
|
@@ -239,7 +236,7 @@ module Parsistence
|
|
239
236
|
end
|
240
237
|
|
241
238
|
# Grab all results that match query
|
242
|
-
#
|
239
|
+
#
|
243
240
|
# @param [Block] callback block
|
244
241
|
# @return [Nil]
|
245
242
|
def all(&callback)
|
@@ -248,14 +245,14 @@ module Parsistence
|
|
248
245
|
end
|
249
246
|
|
250
247
|
# Grab first result that matches query
|
251
|
-
#
|
248
|
+
#
|
252
249
|
# @param [Block] callback block
|
253
250
|
# @return [Nil]
|
254
251
|
def first(&callback)
|
255
252
|
fetchOne(&callback)
|
256
253
|
nil
|
257
254
|
end
|
258
|
-
|
255
|
+
|
259
256
|
# Prints current Query conditions to STDERR
|
260
257
|
def showQuery
|
261
258
|
$stderr.puts "Conditions: #{@conditions.to_s}"
|
@@ -271,7 +268,7 @@ module Parsistence
|
|
271
268
|
end
|
272
269
|
|
273
270
|
# Limit number of results
|
274
|
-
#
|
271
|
+
#
|
275
272
|
# @param [Integer] offset value
|
276
273
|
# @param [Integer] number of results to limit, if not passed, first arg is used for limit
|
277
274
|
# @return [Object] self
|
@@ -286,7 +283,7 @@ module Parsistence
|
|
286
283
|
end
|
287
284
|
|
288
285
|
# Order query results
|
289
|
-
#
|
286
|
+
#
|
290
287
|
# @param [Hash] fields - order-direction
|
291
288
|
# @return [Object] self
|
292
289
|
def order(*fields)
|
@@ -297,7 +294,7 @@ module Parsistence
|
|
297
294
|
end
|
298
295
|
|
299
296
|
# Query for fields where key == value
|
300
|
-
#
|
297
|
+
#
|
301
298
|
# @param [Hash] fields key-value pairs
|
302
299
|
# @return [Object] self
|
303
300
|
def eq(*fields)
|
@@ -308,7 +305,7 @@ module Parsistence
|
|
308
305
|
end
|
309
306
|
|
310
307
|
# Query for fields where key != value
|
311
|
-
#
|
308
|
+
#
|
312
309
|
# @param [Hash] fields key-value pairs
|
313
310
|
# @return [Object] self
|
314
311
|
def notEq(*fields)
|
@@ -319,7 +316,7 @@ module Parsistence
|
|
319
316
|
end
|
320
317
|
|
321
318
|
# Query for fields where key < value
|
322
|
-
#
|
319
|
+
#
|
323
320
|
# @param [Hash] fields key-value pairs
|
324
321
|
# @return [Object] self
|
325
322
|
def lt(*fields)
|
@@ -330,7 +327,7 @@ module Parsistence
|
|
330
327
|
end
|
331
328
|
|
332
329
|
# Query for fields where key > value
|
333
|
-
#
|
330
|
+
#
|
334
331
|
# @param [Hash] fields key-value pairs
|
335
332
|
# @return [Object] self
|
336
333
|
def gt(*fields)
|
@@ -341,7 +338,7 @@ module Parsistence
|
|
341
338
|
end
|
342
339
|
|
343
340
|
# Query for fields where key is in an array of values
|
344
|
-
#
|
341
|
+
#
|
345
342
|
# @param [Hash] fields key-value pairs, value is an array
|
346
343
|
# @return [Object] self
|
347
344
|
def in(*fields)
|
@@ -352,7 +349,7 @@ module Parsistence
|
|
352
349
|
end
|
353
350
|
|
354
351
|
# Query for fields where key <= value
|
355
|
-
#
|
352
|
+
#
|
356
353
|
# @param [Hash] fields key-value pairs
|
357
354
|
# @return [Object] self
|
358
355
|
def lte(*fields)
|
@@ -363,7 +360,7 @@ module Parsistence
|
|
363
360
|
end
|
364
361
|
|
365
362
|
# Query for fields where key >= value
|
366
|
-
#
|
363
|
+
#
|
367
364
|
# @param [Hash] fields key-value pairs
|
368
365
|
# @return [Object] self
|
369
366
|
def gte(*fields)
|
@@ -379,7 +376,7 @@ module Parsistence
|
|
379
376
|
end
|
380
377
|
|
381
378
|
# Include related object in query
|
382
|
-
#
|
379
|
+
#
|
383
380
|
# @param [Hash] fields
|
384
381
|
# @return [Object] self
|
385
382
|
def includes(*fields)
|
@@ -389,4 +386,4 @@ module Parsistence
|
|
389
386
|
self
|
390
387
|
end
|
391
388
|
end
|
392
|
-
end
|
389
|
+
end
|
data/lib/Parsistence/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Parsistence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jamon Holmgren
|
@@ -10,7 +9,7 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2015-07-11 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
14
|
description: Your models on RubyMotion and Parse in a persistence.js style pattern.
|
16
15
|
email:
|
@@ -20,7 +19,7 @@ executables: []
|
|
20
19
|
extensions: []
|
21
20
|
extra_rdoc_files: []
|
22
21
|
files:
|
23
|
-
- .gitignore
|
22
|
+
- ".gitignore"
|
24
23
|
- Gemfile
|
25
24
|
- Parsistence.gemspec
|
26
25
|
- README.md
|
@@ -33,27 +32,25 @@ files:
|
|
33
32
|
- lib/Parsistence/version.rb
|
34
33
|
homepage: https://github.com/clearsightstudio/Parsistence
|
35
34
|
licenses: []
|
35
|
+
metadata: {}
|
36
36
|
post_install_message:
|
37
37
|
rdoc_options: []
|
38
38
|
require_paths:
|
39
39
|
- lib
|
40
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
41
|
requirements:
|
43
|
-
- -
|
42
|
+
- - ">="
|
44
43
|
- !ruby/object:Gem::Version
|
45
44
|
version: '0'
|
46
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
46
|
requirements:
|
49
|
-
- -
|
47
|
+
- - ">="
|
50
48
|
- !ruby/object:Gem::Version
|
51
49
|
version: '0'
|
52
50
|
requirements: []
|
53
51
|
rubyforge_project: Parsistence
|
54
|
-
rubygems_version:
|
52
|
+
rubygems_version: 2.4.8
|
55
53
|
signing_key:
|
56
|
-
specification_version:
|
54
|
+
specification_version: 4
|
57
55
|
summary: Your models on RubyMotion and Parse in a persistence.js style pattern.
|
58
56
|
test_files: []
|
59
|
-
has_rdoc:
|